From d974a07e96199932e98f6c34b8f3e1f151b53500 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 20 Oct 2023 17:38:19 +0000 Subject: [PATCH] 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. --- lightning/src/ln/channelmanager.rs | 8 ++++---- lightning/src/offers/invoice_error.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 4f3caef03..20dba4cf8 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -8967,10 +8967,10 @@ where match invoice.sign(|invoice| self.node_signer.sign_bolt12_invoice(invoice)) { Ok(invoice) => Ok(OffersMessage::Invoice(invoice)), Err(SignError::Signing(())) => Err(OffersMessage::InvoiceError( - InvoiceError::from_str("Failed signing invoice") + InvoiceError::from_string("Failed signing invoice".to_string()) )), Err(SignError::Verification(_)) => Err(OffersMessage::InvoiceError( - InvoiceError::from_str("Failed invoice signature verification") + InvoiceError::from_string("Failed invoice signature verification".to_string()) )), }); match response { @@ -8986,7 +8986,7 @@ where OffersMessage::Invoice(invoice) => { match invoice.verify(expanded_key, secp_ctx) { Err(()) => { - Some(OffersMessage::InvoiceError(InvoiceError::from_str("Unrecognized invoice"))) + Some(OffersMessage::InvoiceError(InvoiceError::from_string("Unrecognized invoice".to_owned()))) }, Ok(_) if invoice.invoice_features().requires_unknown_bits_from(&self.bolt12_invoice_features()) => { Some(OffersMessage::InvoiceError(Bolt12SemanticError::UnknownRequiredFeatures.into())) @@ -8994,7 +8994,7 @@ where Ok(payment_id) => { if let Err(e) = self.send_payment_for_bolt12_invoice(&invoice, payment_id) { log_trace!(self.logger, "Failed paying invoice: {:?}", e); - Some(OffersMessage::InvoiceError(InvoiceError::from_str(&format!("{:?}", e)))) + Some(OffersMessage::InvoiceError(InvoiceError::from_string(format!("{:?}", e)))) } else { None } diff --git a/lightning/src/offers/invoice_error.rs b/lightning/src/offers/invoice_error.rs index 441dae265..5476ad551 100644 --- a/lightning/src/offers/invoice_error.rs +++ b/lightning/src/offers/invoice_error.rs @@ -50,10 +50,10 @@ pub struct ErroneousField { impl InvoiceError { /// Creates an [`InvoiceError`] with the given message. - pub fn from_str(s: &str) -> Self { + pub fn from_string(s: String) -> Self { Self { erroneous_field: None, - message: UntrustedString(s.to_string()), + message: UntrustedString(s), } } } -- 2.39.5