Skip to content

Commit

Permalink
fix: resolve force close amount bug
Browse files Browse the repository at this point in the history
  • Loading branch information
quake committed Jan 30, 2025
1 parent d68a6eb commit ea4609a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/fiber/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6304,7 +6304,7 @@ impl ChannelActorState {
}

fn build_init_commitment_tx_signature(&self) -> Result<PartialSignature, SigningError> {
let sign_ctx = self.get_sign_context(true);
let sign_ctx = self.get_sign_context(false);
let x_only_aggregated_pubkey = sign_ctx.common_ctx.x_only_aggregated_pubkey();
let ([to_local_output, to_remote_output], [to_local_output_data, to_remote_output_data]) =
self.build_settlement_transaction_outputs(false);
Expand Down Expand Up @@ -6334,7 +6334,7 @@ impl ChannelActorState {
&self,
signature: PartialSignature,
) -> Result<SettlementData, ProcessingChannelError> {
let sign_ctx = self.get_sign_context(false);
let sign_ctx = self.get_sign_context(true);
let x_only_aggregated_pubkey = sign_ctx.common_ctx.x_only_aggregated_pubkey();

let ([to_local_output, to_remote_output], [to_local_output_data, to_remote_output_data]) =
Expand Down Expand Up @@ -6823,33 +6823,39 @@ impl ChannelActorState {
let mut received_fullfilled = 0;
for info in pending_tlcs {
if info.is_offered() {
offered_pending += info.amount;
if (info.outbound_status() == OutboundTlcStatus::RemoveWaitAck
|| info.outbound_status() == OutboundTlcStatus::RemoveAckConfirmed)
|| info.outbound_status() == OutboundTlcStatus::RemoveAckConfirmed
|| (info.outbound_status() == OutboundTlcStatus::RemoteRemoved && !for_remote))
&& info
.removed_reason
.as_ref()
.map(|r| matches!(r, RemoveTlcReason::RemoveTlcFulfill(_)))
.unwrap_or_default()
{
offered_fullfilled += info.amount;
} else {
offered_pending += info.amount;
}
} else {
received_pending += info.amount;
if info.inbound_status() == InboundTlcStatus::RemoveAckConfirmed
if (info.inbound_status() == InboundTlcStatus::RemoveAckConfirmed
|| (info.inbound_status() == InboundTlcStatus::LocalRemoved && for_remote))
&& info
.removed_reason
.as_ref()
.map(|r| matches!(r, RemoveTlcReason::RemoveTlcFulfill(_)))
.unwrap_or_default()
{
received_fullfilled += info.amount;
} else {
received_pending += info.amount;
}
}
}

let to_local_value = self.to_local_amount + received_fullfilled - offered_pending;
let to_remote_value = self.to_remote_amount + offered_fullfilled - received_pending;
let to_local_value =
self.to_local_amount + received_fullfilled - offered_pending - offered_fullfilled;
let to_remote_value =
self.to_remote_amount + offered_fullfilled - received_pending - received_fullfilled;

let commitment_tx_fee =
calculate_commitment_tx_fee(self.commitment_fee_rate, &self.funding_udt_type_script);
Expand Down

0 comments on commit ea4609a

Please sign in to comment.