Simplify error return patterns in channel.rs
What changed, and why it matters
This commit is a pure code cleanup: it extracts long error message strings into local variables before building the same error return values. There is no functional change, no security fix, and no change to what the program does.
No action required; this is a non-security refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff refactors error-return sites in lightning/src/ln/channel.rs to reduce nesting and improve readability. In each case a previously inline string literal is assigned to a local err variable, then passed to the same ChannelError::WarnAndDisconnect(...) or ChannelError::close(...) constructor. The generated code behavior is unchanged; no logic, validation, or state handling was modified.
Changed components
lightning/src/ln/channel.rsInspect captured patch +25 / −47
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 3667e08..57f1020 100644
--- a/lightning/src/ln/channel.rs
+++ b/lightning/src/ln/channel.rs
@@ -1914,13 +1914,8 @@ where
.handle_tx_complete(msg)
.map_err(|reason| self.fail_interactive_tx_negotiation(reason, logger))?,
None => {
- return Err((
- ChannelError::WarnAndDisconnect(
- "Received unexpected interactive transaction negotiation message"
- .to_owned(),
- ),
- None,
- ))
+ let err = "Received unexpected interactive transaction negotiation message";
+ return Err((ChannelError::WarnAndDisconnect(err.to_owned()), None));
},
};
@@ -13806,28 +13801,20 @@ where
L::Target: Logger,
{
if !self.funding.is_outbound() {
- return Err((
- self,
- ChannelError::close("Received funding_signed for an inbound channel?".to_owned()),
- ));
+ let err = "Received funding_signed for an inbound channel?";
+ return Err((self, ChannelError::close(err.to_owned())));
}
if !matches!(self.context.channel_state, ChannelState::FundingNegotiated(_)) {
- return Err((
- self,
- ChannelError::close("Received funding_signed in strange state!".to_owned()),
- ));
+ let err = "Received funding_signed in strange state!";
+ return Err((self, ChannelError::close(err.to_owned())));
}
- let mut holder_commitment_point =
- match self.unfunded_context.holder_commitment_point {
- Some(point) => point,
- None => return Err((
- self,
- ChannelError::close(
- "Received funding_signed before our first commitment point was available"
- .to_owned(),
- ),
- )),
- };
+ let mut holder_commitment_point = match self.unfunded_context.holder_commitment_point {
+ Some(point) => point,
+ None => {
+ let err = "Received funding_signed before our first commitment point was available";
+ return Err((self, ChannelError::close(err.to_owned())));
+ },
+ };
self.context.assert_no_commitment_advancement(
holder_commitment_point.next_transaction_number(),
"funding_signed",
@@ -14117,10 +14104,8 @@ where
L::Target: Logger,
{
if self.funding.is_outbound() {
- return Err((
- self,
- ChannelError::close("Received funding_created for an outbound channel?".to_owned()),
- ));
+ let err = "Received funding_created for an outbound channel?";
+ return Err((self, ChannelError::close(err.to_owned())));
}
if !matches!(
self.context.channel_state, ChannelState::NegotiatingFunding(flags)
@@ -14129,24 +14114,17 @@ where
// BOLT 2 says that if we disconnect before we send funding_signed we SHOULD NOT
// remember the channel, so it's safe to just send an error_message here and drop the
// channel.
- return Err((
- self,
- ChannelError::close(
- "Received funding_created after we got the channel!".to_owned(),
- ),
- ));
+ let err = "Received funding_created after we got the channel!";
+ return Err((self, ChannelError::close(err.to_owned())));
}
- let mut holder_commitment_point =
- match self.unfunded_context.holder_commitment_point {
- Some(point) => point,
- None => return Err((
- self,
- ChannelError::close(
- "Received funding_created before our first commitment point was available"
- .to_owned(),
- ),
- )),
- };
+ let mut holder_commitment_point = match self.unfunded_context.holder_commitment_point {
+ Some(point) => point,
+ None => {
+ let err =
+ "Received funding_created before our first commitment point was available";
+ return Err((self, ChannelError::close(err.to_owned())));
+ },
+ };
self.context.assert_no_commitment_advancement(
holder_commitment_point.next_transaction_number(),
"funding_created",
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.