Skip to content

Commit 13a910b

Browse files
committed
Simplify error return patterns in channel.rs
Extract error message strings into local variables before constructing ChannelError return tuples, reducing nesting and improving readability.
1 parent a822f52 commit 13a910b

File tree

1 file changed

+25
-47
lines changed

1 file changed

+25
-47
lines changed

lightning/src/ln/channel.rs

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,13 +1914,8 @@ where
19141914
.handle_tx_complete(msg)
19151915
.map_err(|reason| self.fail_interactive_tx_negotiation(reason, logger))?,
19161916
None => {
1917-
return Err((
1918-
ChannelError::WarnAndDisconnect(
1919-
"Received unexpected interactive transaction negotiation message"
1920-
.to_owned(),
1921-
),
1922-
None,
1923-
))
1917+
let err = "Received unexpected interactive transaction negotiation message";
1918+
return Err((ChannelError::WarnAndDisconnect(err.to_owned()), None));
19241919
},
19251920
};
19261921

@@ -13805,28 +13800,20 @@ where
1380513800
L::Target: Logger,
1380613801
{
1380713802
if !self.funding.is_outbound() {
13808-
return Err((
13809-
self,
13810-
ChannelError::close("Received funding_signed for an inbound channel?".to_owned()),
13811-
));
13803+
let err = "Received funding_signed for an inbound channel?";
13804+
return Err((self, ChannelError::close(err.to_owned())));
1381213805
}
1381313806
if !matches!(self.context.channel_state, ChannelState::FundingNegotiated(_)) {
13814-
return Err((
13815-
self,
13816-
ChannelError::close("Received funding_signed in strange state!".to_owned()),
13817-
));
13807+
let err = "Received funding_signed in strange state!";
13808+
return Err((self, ChannelError::close(err.to_owned())));
1381813809
}
13819-
let mut holder_commitment_point =
13820-
match self.unfunded_context.holder_commitment_point {
13821-
Some(point) => point,
13822-
None => return Err((
13823-
self,
13824-
ChannelError::close(
13825-
"Received funding_signed before our first commitment point was available"
13826-
.to_owned(),
13827-
),
13828-
)),
13829-
};
13810+
let mut holder_commitment_point = match self.unfunded_context.holder_commitment_point {
13811+
Some(point) => point,
13812+
None => {
13813+
let err = "Received funding_signed before our first commitment point was available";
13814+
return Err((self, ChannelError::close(err.to_owned())));
13815+
},
13816+
};
1383013817
self.context.assert_no_commitment_advancement(
1383113818
holder_commitment_point.next_transaction_number(),
1383213819
"funding_signed",
@@ -14116,10 +14103,8 @@ where
1411614103
L::Target: Logger,
1411714104
{
1411814105
if self.funding.is_outbound() {
14119-
return Err((
14120-
self,
14121-
ChannelError::close("Received funding_created for an outbound channel?".to_owned()),
14122-
));
14106+
let err = "Received funding_created for an outbound channel?";
14107+
return Err((self, ChannelError::close(err.to_owned())));
1412314108
}
1412414109
if !matches!(
1412514110
self.context.channel_state, ChannelState::NegotiatingFunding(flags)
@@ -14128,24 +14113,17 @@ where
1412814113
// BOLT 2 says that if we disconnect before we send funding_signed we SHOULD NOT
1412914114
// remember the channel, so it's safe to just send an error_message here and drop the
1413014115
// channel.
14131-
return Err((
14132-
self,
14133-
ChannelError::close(
14134-
"Received funding_created after we got the channel!".to_owned(),
14135-
),
14136-
));
14116+
let err = "Received funding_created after we got the channel!";
14117+
return Err((self, ChannelError::close(err.to_owned())));
1413714118
}
14138-
let mut holder_commitment_point =
14139-
match self.unfunded_context.holder_commitment_point {
14140-
Some(point) => point,
14141-
None => return Err((
14142-
self,
14143-
ChannelError::close(
14144-
"Received funding_created before our first commitment point was available"
14145-
.to_owned(),
14146-
),
14147-
)),
14148-
};
14119+
let mut holder_commitment_point = match self.unfunded_context.holder_commitment_point {
14120+
Some(point) => point,
14121+
None => {
14122+
let err =
14123+
"Received funding_created before our first commitment point was available";
14124+
return Err((self, ChannelError::close(err.to_owned())));
14125+
},
14126+
};
1414914127
self.context.assert_no_commitment_advancement(
1415014128
holder_commitment_point.next_transaction_number(),
1415114129
"funding_created",

0 commit comments

Comments
 (0)