From 22018014cac2cdb5f57ffdb22d86f86d5dbd1900 Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Tue, 8 Apr 2025 16:30:11 +0200 Subject: [PATCH] put route hints in email --- src/email.rs | 28 +++++++++++++++++++++++++++- src/htlc_manager.rs | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/email.rs b/src/email.rs index 0c61cc6..088758a 100644 --- a/src/email.rs +++ b/src/email.rs @@ -4,6 +4,7 @@ use aws_sdk_sesv2::{ types::{Body, Content, Destination, EmailContent, Message}, Client, }; +use lightning_invoice::RouteHint; #[cfg(test)] use mockall::automock; use secp256k1::{hashes::sha256, PublicKey}; @@ -12,21 +13,37 @@ use tracing::{debug, error, warn}; pub struct NotifyPaymentFailedRequest { pub destination: PublicKey, pub error: anyhow::Error, + pub hints: Vec, pub payment_hash: sha256::Hash, pub invoice: String, } impl NotifyPaymentFailedRequest { pub fn to_html(&self) -> impl Into { + let hints: Vec<_> = self + .hints + .iter() + .filter_map(|r| r.0.last()) + .enumerate() + .map(|(i, hint)| { + format!( + "Route hint {}: {}, {}", + i, + hint.src_node_id, + scid_to_string(hint.short_channel_id), + ) + }) + .collect(); format!( " - + {}
Destination: {}
Destination: {}
Error: {}
Payment hash: {}
Invoice: {}
", self.destination, + hints.join(""), self.error .to_string() .replace("&", "&") @@ -41,6 +58,15 @@ impl NotifyPaymentFailedRequest { } } +fn scid_to_string(scid: u64) -> String { + format!( + "{}x{}x{}", + scid >> 40, + (scid >> 16) & 0xFFFFFF, + scid & 0xFFFF + ) +} + #[cfg_attr(test, automock)] #[async_trait::async_trait] pub trait NotificationService { diff --git a/src/htlc_manager.rs b/src/htlc_manager.rs index d98cd21..0590019 100644 --- a/src/htlc_manager.rs +++ b/src/htlc_manager.rs @@ -652,6 +652,7 @@ async fn payment_lifecycle( .notify_payment_failed(NotifyPaymentFailedRequest { destination: trampoline.payee, error: e, + hints: trampoline.invoice.route_hints(), payment_hash: *trampoline.invoice.payment_hash(), invoice: trampoline.bolt11, })