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 Dec 10, 2024
1 parent 0e5e817 commit 5dc3678
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,21 +1152,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),
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 @@ -1199,14 +1184,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 @@ -1215,14 +1199,29 @@ 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),
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 5dc3678

Please sign in to comment.