Skip to content

Commit 1f726bd

Browse files
committed
sim-node: make HTLC removal inclusive of zero values
With the previous code, our removal loop would not execute for a resolution index of zero. To fix this, we make the loop inclusive and provide the appropriate index for successful HTLCs (failing HTLCs already use the correct failure index).
1 parent 2bce597 commit 1f726bd

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

sim-lib/src/sim_node.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ async fn remove_htlcs(
894894
payment_hash: PaymentHash,
895895
success: bool,
896896
) -> Result<(), ForwardingError> {
897-
for (i, hop) in route.hops[0..resolution_idx].iter().enumerate().rev() {
897+
for (i, hop) in route.hops[0..=resolution_idx].iter().enumerate().rev() {
898898
// When we add HTLCs, we do so on the state of the node that sent the htlc along the channel so we need to
899899
// look up our incoming node so that we can remove it when we go backwards. For the first htlc, this is just
900900
// the sending node, otherwise it's the hop before.
@@ -967,8 +967,15 @@ async fn propagate_payment(
967967
}
968968
} else {
969969
// If we successfully added the htlc, go ahead and remove all the htlcs in the route with successful resolution.
970-
if let Err(e) =
971-
remove_htlcs(nodes, route.hops.len(), source, route, payment_hash, true).await
970+
if let Err(e) = remove_htlcs(
971+
nodes,
972+
route.hops.len() - 1,
973+
source,
974+
route,
975+
payment_hash,
976+
true,
977+
)
978+
.await
972979
{
973980
if e.is_critical() {
974981
shutdown.trigger();

0 commit comments

Comments
 (0)