Skip to content

Commit 0e6532d

Browse files
committed
Move PaymentForwarded event emission down
.. to align with other event handling variants: First log, then act, then emit event if everything went okay.
1 parent 22ca418 commit 0e6532d

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/event.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -1152,21 +1152,6 @@ where
11521152
claim_from_onchain_tx,
11531153
outbound_amount_forwarded_msat,
11541154
} => {
1155-
let event = Event::PaymentForwarded {
1156-
prev_channel_id: prev_channel_id.expect("prev_channel_id expected for events generated by LDK versions greater than 0.0.107."),
1157-
next_channel_id: next_channel_id.expect("next_channel_id expected for events generated by LDK versions greater than 0.0.107."),
1158-
prev_user_channel_id: prev_user_channel_id.map(UserChannelId),
1159-
next_user_channel_id: next_user_channel_id.map(UserChannelId),
1160-
total_fee_earned_msat,
1161-
skimmed_fee_msat,
1162-
claim_from_onchain_tx,
1163-
outbound_amount_forwarded_msat,
1164-
};
1165-
self.event_queue.add_event(event).map_err(|e| {
1166-
log_error!(self.logger, "Failed to push to event queue: {}", e);
1167-
ReplayEvent()
1168-
})?;
1169-
11701155
let read_only_network_graph = self.network_graph.read_only();
11711156
let nodes = read_only_network_graph.nodes();
11721157
let channels = self.channel_manager.list_channels();
@@ -1199,14 +1184,13 @@ where
11991184
format!(" to {}{}", node_str(&next_channel_id), channel_str(&next_channel_id));
12001185

12011186
let fee_earned = total_fee_earned_msat.unwrap_or(0);
1202-
let outbound_amount_forwarded_msat = outbound_amount_forwarded_msat.unwrap_or(0);
12031187
if claim_from_onchain_tx {
12041188
log_info!(
12051189
self.logger,
12061190
"Forwarded payment{}{} of {}msat, earning {}msat in fees from claiming onchain.",
12071191
from_prev_str,
12081192
to_next_str,
1209-
outbound_amount_forwarded_msat,
1193+
outbound_amount_forwarded_msat.unwrap_or(0),
12101194
fee_earned,
12111195
);
12121196
} else {
@@ -1215,14 +1199,29 @@ where
12151199
"Forwarded payment{}{} of {}msat, earning {}msat in fees.",
12161200
from_prev_str,
12171201
to_next_str,
1218-
outbound_amount_forwarded_msat,
1202+
outbound_amount_forwarded_msat.unwrap_or(0),
12191203
fee_earned,
12201204
);
12211205
}
12221206

12231207
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
12241208
liquidity_source.handle_payment_forwarded(next_channel_id);
12251209
}
1210+
1211+
let event = Event::PaymentForwarded {
1212+
prev_channel_id: prev_channel_id.expect("prev_channel_id expected for events generated by LDK versions greater than 0.0.107."),
1213+
next_channel_id: next_channel_id.expect("next_channel_id expected for events generated by LDK versions greater than 0.0.107."),
1214+
prev_user_channel_id: prev_user_channel_id.map(UserChannelId),
1215+
next_user_channel_id: next_user_channel_id.map(UserChannelId),
1216+
total_fee_earned_msat,
1217+
skimmed_fee_msat,
1218+
claim_from_onchain_tx,
1219+
outbound_amount_forwarded_msat,
1220+
};
1221+
self.event_queue.add_event(event).map_err(|e| {
1222+
log_error!(self.logger, "Failed to push to event queue: {}", e);
1223+
ReplayEvent()
1224+
})?;
12261225
},
12271226
LdkEvent::ChannelPending {
12281227
channel_id,

0 commit comments

Comments
 (0)