Skip to content

Commit 2bce597

Browse files
committed
sim-node: do not double count failed HTLC in local balance
We handle balances in settle_htlc, so do not need to shift local balance in remove_outgoing_htlc.
1 parent c3292a8 commit 2bce597

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

sim-lib/src/sim_node.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -225,26 +225,11 @@ impl ChannelState {
225225
Ok(())
226226
}
227227

228-
/// Removes the HTLC from our set of outgoing in-flight HTLCs, failing if the payment hash is not found. If the
229-
/// HTLC failed, the balance is returned to our local liquidity. Note that this function is not responsible for
230-
/// reflecting that the balance has moved to the other side of the channel in the success-case, calling code is
231-
/// responsible for that.
232-
fn remove_outgoing_htlc(
233-
&mut self,
234-
hash: &PaymentHash,
235-
success: bool,
236-
) -> Result<Htlc, ForwardingError> {
237-
match self.in_flight.remove(hash) {
238-
Some(v) => {
239-
// If the HTLC failed, pending balance returns to local balance.
240-
if !success {
241-
self.local_balance_msat += v.amount_msat;
242-
}
243-
244-
Ok(v)
245-
},
246-
None => Err(ForwardingError::PaymentHashNotFound(*hash)),
247-
}
228+
/// Removes the HTLC from our set of outgoing in-flight HTLCs, failing if the payment hash is not found.
229+
fn remove_outgoing_htlc(&mut self, hash: &PaymentHash) -> Result<Htlc, ForwardingError> {
230+
self.in_flight
231+
.remove(hash)
232+
.ok_or(ForwardingError::PaymentHashNotFound(*hash))
248233
}
249234
}
250235

@@ -349,7 +334,7 @@ impl SimulatedChannel {
349334
) -> Result<(), ForwardingError> {
350335
let htlc = self
351336
.get_node_mut(sending_node)?
352-
.remove_outgoing_htlc(hash, success)?;
337+
.remove_outgoing_htlc(hash)?;
353338
self.settle_htlc(sending_node, htlc.amount_msat, success)?;
354339
self.sanity_check()
355340
}

0 commit comments

Comments
 (0)