Skip to content

Commit d974a07

Browse files
committed
Avoid a redundant allocation in InvoiceError handling in one case
... by passing an owned `String`, rather than taking an `&str` and `to_owned()`ing it.
1 parent 50c55dc commit d974a07

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8967,10 +8967,10 @@ where
89678967
match invoice.sign(|invoice| self.node_signer.sign_bolt12_invoice(invoice)) {
89688968
Ok(invoice) => Ok(OffersMessage::Invoice(invoice)),
89698969
Err(SignError::Signing(())) => Err(OffersMessage::InvoiceError(
8970-
InvoiceError::from_str("Failed signing invoice")
8970+
InvoiceError::from_string("Failed signing invoice".to_string())
89718971
)),
89728972
Err(SignError::Verification(_)) => Err(OffersMessage::InvoiceError(
8973-
InvoiceError::from_str("Failed invoice signature verification")
8973+
InvoiceError::from_string("Failed invoice signature verification".to_string())
89748974
)),
89758975
});
89768976
match response {
@@ -8986,15 +8986,15 @@ where
89868986
OffersMessage::Invoice(invoice) => {
89878987
match invoice.verify(expanded_key, secp_ctx) {
89888988
Err(()) => {
8989-
Some(OffersMessage::InvoiceError(InvoiceError::from_str("Unrecognized invoice")))
8989+
Some(OffersMessage::InvoiceError(InvoiceError::from_string("Unrecognized invoice".to_owned())))
89908990
},
89918991
Ok(_) if invoice.invoice_features().requires_unknown_bits_from(&self.bolt12_invoice_features()) => {
89928992
Some(OffersMessage::InvoiceError(Bolt12SemanticError::UnknownRequiredFeatures.into()))
89938993
},
89948994
Ok(payment_id) => {
89958995
if let Err(e) = self.send_payment_for_bolt12_invoice(&invoice, payment_id) {
89968996
log_trace!(self.logger, "Failed paying invoice: {:?}", e);
8997-
Some(OffersMessage::InvoiceError(InvoiceError::from_str(&format!("{:?}", e))))
8997+
Some(OffersMessage::InvoiceError(InvoiceError::from_string(format!("{:?}", e))))
89988998
} else {
89998999
None
90009000
}

lightning/src/offers/invoice_error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ pub struct ErroneousField {
5050

5151
impl InvoiceError {
5252
/// Creates an [`InvoiceError`] with the given message.
53-
pub fn from_str(s: &str) -> Self {
53+
pub fn from_string(s: String) -> Self {
5454
Self {
5555
erroneous_field: None,
56-
message: UntrustedString(s.to_string()),
56+
message: UntrustedString(s),
5757
}
5858
}
5959
}

0 commit comments

Comments
 (0)