Skip to content

Commit

Permalink
delete i64s
Browse files Browse the repository at this point in the history
  • Loading branch information
tankyleo committed Feb 23, 2025
1 parent ee28c63 commit b53abfc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
}
}

let value_to_self_msat: i64 = self.value_to_self_msat as i64 + value_to_self_msat_offset;
let value_to_self_msat: u64 = u64::try_from((self.value_to_self_msat as i64) + value_to_self_msat_offset).unwrap();

use crate::sign::tx_builder::SpecTxBuilder;
use crate::sign::tx_builder::TxBuilder;
Expand Down
24 changes: 10 additions & 14 deletions lightning/src/sign/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) trait TxBuilder {
fn build_commitment_transaction<'a>(
&self, local: bool, commitment_number: u64, per_commitment_point: &PublicKey,
channel_parameters: &ChannelTransactionParameters, secp_ctx: &Secp256k1<secp256k1::All>,
channel_value_satoshis: u64, value_to_self_msat: i64,
channel_value_satoshis: u64, value_to_self_msat: u64,
htlcs_in_tx: Vec<(HTLCOutputInCommitment, Option<&'a HTLCSource>)>, feerate_per_kw: u32,
broadcaster_dust_limit_satoshis: u64,
) -> CommitmentStats<'a>;
Expand All @@ -36,7 +36,7 @@ impl TxBuilder for SpecTxBuilder {
fn build_commitment_transaction<'a>(
&self, local: bool, commitment_number: u64, per_commitment_point: &PublicKey,
channel_parameters: &ChannelTransactionParameters, secp_ctx: &Secp256k1<secp256k1::All>,
channel_value_satoshis: u64, mut value_to_self_msat: i64,
channel_value_satoshis: u64, mut value_to_self_msat: u64,
htlcs_in_tx: Vec<(HTLCOutputInCommitment, Option<&'a HTLCSource>)>, feerate_per_kw: u32,
broadcaster_dust_limit_satoshis: u64,
) -> CommitmentStats<'a> {
Expand Down Expand Up @@ -94,10 +94,9 @@ impl TxBuilder for SpecTxBuilder {
}
}

let mut value_to_remote_msat: i64 =
(channel_value_satoshis * 1000) as i64 - value_to_self_msat;
value_to_self_msat -= local_htlc_total_msat as i64;
value_to_remote_msat -= remote_htlc_total_msat as i64;
let mut value_to_remote_msat = u64::checked_sub(channel_value_satoshis * 1000, value_to_self_msat).unwrap();
value_to_self_msat = u64::checked_sub(value_to_self_msat, local_htlc_total_msat).unwrap();
value_to_remote_msat = u64::checked_sub(value_to_remote_msat, remote_htlc_total_msat).unwrap();

let total_fee_sat = chan_utils::commit_tx_fee_sat(
feerate_per_kw,
Expand All @@ -108,16 +107,16 @@ impl TxBuilder for SpecTxBuilder {
crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI * 2
} else {
0
} as i64;
};
let (value_to_self, value_to_remote) = if channel_parameters.is_outbound_from_holder {
(
value_to_self_msat / 1000 - anchors_val - total_fee_sat as i64,
(value_to_self_msat / 1000).saturating_sub(anchors_val).saturating_sub(total_fee_sat),
value_to_remote_msat / 1000,
)
} else {
(
value_to_self_msat / 1000,
value_to_remote_msat / 1000 - anchors_val - total_fee_sat as i64,
(value_to_remote_msat / 1000).saturating_sub(anchors_val).saturating_sub(total_fee_sat),
)
};

Expand All @@ -128,13 +127,13 @@ impl TxBuilder for SpecTxBuilder {
params.countersignatory_pubkeys().funding_pubkey,
);

if value_to_a >= (broadcaster_dust_limit_satoshis as i64) {
if value_to_a >= broadcaster_dust_limit_satoshis {
//log_trace!(logger, " ...including {} output with value {}", if local { "to_local" } else { "to_remote" }, value_to_a);
} else {
value_to_a = 0;
}

if value_to_b >= (broadcaster_dust_limit_satoshis as i64) {
if value_to_b >= broadcaster_dust_limit_satoshis {
//log_trace!(logger, " ...including {} output with value {}", if local { "to_remote" } else { "to_local" }, value_to_b);
} else {
value_to_b = 0;
Expand All @@ -158,9 +157,6 @@ impl TxBuilder for SpecTxBuilder {
&mut included_non_dust_htlcs,
&params,
);
// TODO: do checked subs
// checkout the debug assertions we deleted
// do we need to return the trimmed sum / value ?

included_non_dust_htlcs.sort_unstable_by_key(|h| h.0.transaction_output_index.unwrap());
let num_nondust_htlcs = included_non_dust_htlcs.len();
Expand Down

0 comments on commit b53abfc

Please sign in to comment.