Skip to content

Commit e141bec

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 cb4995b commit e141bec

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/event.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,21 +1137,6 @@ where
11371137
claim_from_onchain_tx,
11381138
outbound_amount_forwarded_msat,
11391139
} => {
1140-
let event = Event::PaymentForwarded {
1141-
prev_channel_id: prev_channel_id.expect("prev_channel_id expected for events generated by LDK versions greater than 0.0.107."),
1142-
next_channel_id: next_channel_id.expect("next_channel_id expected for events generated by LDK versions greater than 0.0.107."),
1143-
prev_user_channel_id: prev_user_channel_id.map(UserChannelId),
1144-
next_user_channel_id: next_user_channel_id.map(UserChannelId),
1145-
total_fee_earned_msat,
1146-
skimmed_fee_msat,
1147-
claim_from_onchain_tx,
1148-
outbound_amount_forwarded_msat,
1149-
};
1150-
self.event_queue.add_event(event).map_err(|e| {
1151-
log_error!(self.logger, "Failed to push to event queue: {}", e);
1152-
ReplayEvent()
1153-
})?;
1154-
11551140
let read_only_network_graph = self.network_graph.read_only();
11561141
let nodes = read_only_network_graph.nodes();
11571142
let channels = self.channel_manager.list_channels();
@@ -1184,14 +1169,13 @@ where
11841169
format!(" to {}{}", node_str(&next_channel_id), channel_str(&next_channel_id));
11851170

11861171
let fee_earned = total_fee_earned_msat.unwrap_or(0);
1187-
let outbound_amount_forwarded_msat = outbound_amount_forwarded_msat.unwrap_or(0);
11881172
if claim_from_onchain_tx {
11891173
log_info!(
11901174
self.logger,
11911175
"Forwarded payment{}{} of {}msat, earning {}msat in fees from claiming onchain.",
11921176
from_prev_str,
11931177
to_next_str,
1194-
outbound_amount_forwarded_msat,
1178+
outbound_amount_forwarded_msat.unwrap_or(0),
11951179
fee_earned,
11961180
);
11971181
} else {
@@ -1200,14 +1184,29 @@ where
12001184
"Forwarded payment{}{} of {}msat, earning {}msat in fees.",
12011185
from_prev_str,
12021186
to_next_str,
1203-
outbound_amount_forwarded_msat,
1187+
outbound_amount_forwarded_msat.unwrap_or(0),
12041188
fee_earned,
12051189
);
12061190
}
12071191

12081192
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
12091193
liquidity_source.handle_payment_forwarded(next_channel_id);
12101194
}
1195+
1196+
let event = Event::PaymentForwarded {
1197+
prev_channel_id: prev_channel_id.expect("prev_channel_id expected for events generated by LDK versions greater than 0.0.107."),
1198+
next_channel_id: next_channel_id.expect("next_channel_id expected for events generated by LDK versions greater than 0.0.107."),
1199+
prev_user_channel_id: prev_user_channel_id.map(UserChannelId),
1200+
next_user_channel_id: next_user_channel_id.map(UserChannelId),
1201+
total_fee_earned_msat,
1202+
skimmed_fee_msat,
1203+
claim_from_onchain_tx,
1204+
outbound_amount_forwarded_msat,
1205+
};
1206+
self.event_queue.add_event(event).map_err(|e| {
1207+
log_error!(self.logger, "Failed to push to event queue: {}", e);
1208+
ReplayEvent()
1209+
})?;
12111210
},
12121211
LdkEvent::ChannelPending {
12131212
channel_id,

0 commit comments

Comments
 (0)