Skip to content

Commit

Permalink
Move PaymentForwarded event emission down
Browse files Browse the repository at this point in the history
.. to align with other event handling variants: First log, then act,
then emit event if everything went okay.
  • Loading branch information
tnull committed Feb 6, 2025
1 parent d98ff98 commit 6d387ee
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,23 +1170,6 @@ where
claim_from_onchain_tx,
outbound_amount_forwarded_msat,
} => {
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."),
prev_user_channel_id: prev_user_channel_id.map(UserChannelId),
next_user_channel_id: next_user_channel_id.map(UserChannelId),
prev_node_id,
next_node_id,
total_fee_earned_msat,
skimmed_fee_msat,
claim_from_onchain_tx,
outbound_amount_forwarded_msat,
};
self.event_queue.add_event(event).map_err(|e| {
log_error!(self.logger, "Failed to push to event queue: {}", e);
ReplayEvent()
})?;

let read_only_network_graph = self.network_graph.read_only();
let nodes = read_only_network_graph.nodes();
let channels = self.channel_manager.list_channels();
Expand Down Expand Up @@ -1219,14 +1202,13 @@ where
format!(" to {}{}", node_str(&next_channel_id), channel_str(&next_channel_id));

let fee_earned = total_fee_earned_msat.unwrap_or(0);
let outbound_amount_forwarded_msat = outbound_amount_forwarded_msat.unwrap_or(0);
if claim_from_onchain_tx {
log_info!(
self.logger,
"Forwarded payment{}{} of {}msat, earning {}msat in fees from claiming onchain.",
from_prev_str,
to_next_str,
outbound_amount_forwarded_msat,
outbound_amount_forwarded_msat.unwrap_or(0),
fee_earned,
);
} else {
Expand All @@ -1235,14 +1217,31 @@ where
"Forwarded payment{}{} of {}msat, earning {}msat in fees.",
from_prev_str,
to_next_str,
outbound_amount_forwarded_msat,
outbound_amount_forwarded_msat.unwrap_or(0),
fee_earned,
);
}

if let Some(liquidity_source) = self.liquidity_source.as_ref() {
liquidity_source.handle_payment_forwarded(next_channel_id);
}

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."),
prev_user_channel_id: prev_user_channel_id.map(UserChannelId),
next_user_channel_id: next_user_channel_id.map(UserChannelId),
prev_node_id,
next_node_id,
total_fee_earned_msat,
skimmed_fee_msat,
claim_from_onchain_tx,
outbound_amount_forwarded_msat,
};
self.event_queue.add_event(event).map_err(|e| {
log_error!(self.logger, "Failed to push to event queue: {}", e);
ReplayEvent()
})?;
},
LdkEvent::ChannelPending {
channel_id,
Expand Down

0 comments on commit 6d387ee

Please sign in to comment.