Skip to content

Commit

Permalink
Fix balance calculation in removing tlc
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Jun 14, 2024
1 parent d97b639 commit 7bf2b7c
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/ckb/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1785,13 +1785,14 @@ impl ChannelActorState {
}
}
// We are sure that this tlc removal is not repeated and the reason is valid now.
match reason {
RemoveTlcReason::RemoveTlcFail(_) => {
self.to_remote_amount += current.tlc.amount;
}
RemoveTlcReason::RemoveTlcFulfill(_) => {
self.to_local_amount += current.tlc.amount;
}
let should_increase_our_balance = match reason {
RemoveTlcReason::RemoveTlcFulfill(_) => tlc_id.is_received(),
RemoveTlcReason::RemoveTlcFail(_) => tlc_id.is_offered(),
};
if should_increase_our_balance {
self.to_local_amount += current.tlc.amount;
} else {
self.to_remote_amount += current.tlc.amount;
}
current.removal_info = Some((commitment_numbers, reason));
Ok(current.clone())
Expand Down Expand Up @@ -3171,7 +3172,13 @@ impl ChannelActorState {

// The time_locked_value is amount of assets locked by commitment-lock.
// We need also to include the total balance of all pending TLCs.
let time_locked_value = time_locked_value + self.get_active_tlcs_value();
let tlc_value = self.get_active_tlcs_value();
debug!(
"Got {} commitment transaction #{}'s values: time_locked_value: {}, tlc_vle: {}, immediately_spendable_value: {}",
if local { "local" } else { "remote" },
self.get_current_commitment_number(local),
time_locked_value, tlc_value, immediately_spendable_value);
let time_locked_value = time_locked_value + tlc_value;

let immediate_payment_key = {
let (commitment_point, base_payment_key) = if local {
Expand Down

0 comments on commit 7bf2b7c

Please sign in to comment.