Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,7 @@ fn build_with_store_internal(
node_metrics,
om_mailbox,
async_payments_role,
forward_counters: Arc::new(crate::ForwardCounters::new()),
})
}

Expand Down
51 changes: 47 additions & 4 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use crate::io::{
EVENT_QUEUE_PERSISTENCE_KEY, EVENT_QUEUE_PERSISTENCE_PRIMARY_NAMESPACE,
EVENT_QUEUE_PERSISTENCE_SECONDARY_NAMESPACE,
};
use crate::forward_metrics::ForwardCounters;
use crate::liquidity::LiquiditySource;
use crate::logger::{log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
use crate::payment::asynchronous::om_mailbox::OnionMessageMailbox;
Expand Down Expand Up @@ -505,6 +506,7 @@ where
static_invoice_store: Option<StaticInvoiceStore>,
onion_messenger: Arc<OnionMessenger>,
om_mailbox: Option<Arc<OnionMessageMailbox>>,
forward_counters: Arc<ForwardCounters>,
}

impl<L: Deref + Clone + Sync + Send + 'static> EventHandler<L>
Expand All @@ -520,7 +522,7 @@ where
payment_store: Arc<PaymentStore>, peer_store: Arc<PeerStore<L>>,
static_invoice_store: Option<StaticInvoiceStore>, onion_messenger: Arc<OnionMessenger>,
om_mailbox: Option<Arc<OnionMessageMailbox>>, runtime: Arc<Runtime>, logger: L,
config: Arc<Config>,
config: Arc<Config>, forward_counters: Arc<ForwardCounters>,
) -> Self {
Self {
event_queue,
Expand All @@ -539,6 +541,7 @@ where
static_invoice_store,
onion_messenger,
om_mailbox,
forward_counters,
}
}

Expand Down Expand Up @@ -1125,9 +1128,40 @@ where
LdkEvent::PaymentPathFailed { .. } => {},
LdkEvent::ProbeSuccessful { .. } => {},
LdkEvent::ProbeFailed { .. } => {},
LdkEvent::HTLCHandlingFailed { failure_type, .. } => {
LdkEvent::HTLCHandlingFailed {
prev_channel_id,
failure_type,
failure_reason,
} => {
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
liquidity_source.handle_htlc_handling_failed(failure_type).await;
liquidity_source
.handle_htlc_handling_failed(failure_type.clone())
.await;
}

match &failure_type {
lightning::events::HTLCHandlingFailureType::Forward {
channel_id: next_channel_id,
..
} => {
let channels = self.channel_manager.list_channels();
if let Some(dir) = ForwardCounters::classify(
&channels,
&prev_channel_id,
next_channel_id,
) {
let is_downstream = matches!(
failure_reason,
Some(lightning::events::HTLCHandlingFailureReason::Downstream)
);
self.forward_counters.record_failure(dir, is_downstream);
}
},
lightning::events::HTLCHandlingFailureType::UnknownNextHop { .. }
| lightning::events::HTLCHandlingFailureType::InvalidForward { .. } => {
self.forward_counters.record_invalid_scid();
},
_ => {},
}
},
LdkEvent::SpendableOutputs { outputs, channel_id } => {
Expand Down Expand Up @@ -1308,10 +1342,11 @@ where
claim_from_onchain_tx,
outbound_amount_forwarded_msat,
} => {
let channels = self.channel_manager.list_channels();

{
let read_only_network_graph = self.network_graph.read_only();
let nodes = read_only_network_graph.nodes();
let channels = self.channel_manager.list_channels();

let node_str = |channel_id: &Option<ChannelId>| {
channel_id
Expand Down Expand Up @@ -1374,6 +1409,14 @@ where
.await;
}

if let (Some(prev_cid), Some(next_cid)) = (prev_channel_id, next_channel_id) {
if let Some(dir) =
ForwardCounters::classify(&channels, &prev_cid, &next_cid)
{
self.forward_counters.record_success(dir);
}
}

let event = Event::PaymentForwarded {
prev_channel_id: prev_channel_id.expect("prev_channel_id expected for events generated by LDK versions greater than 0.0.107."),
next_channel_id: next_channel_id.expect("next_channel_id expected for events generated by LDK versions greater than 0.0.107."),
Expand Down
Loading
Loading