Skip to content

Commit 7077eb1

Browse files
committed
Rename method, review
1 parent fa452ad commit 7077eb1

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

lightning/src/ln/channel.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::ln::types::ChannelId;
3131
use crate::types::payment::{PaymentPreimage, PaymentHash};
3232
use crate::types::features::{ChannelTypeFeatures, InitFeatures};
3333
use crate::ln::interactivetxs::{
34-
get_output_weight, need_to_add_funding_change_output, HandleTxCompleteValue, HandleTxCompleteResult, InteractiveTxConstructor,
34+
get_output_weight, calculate_change_output_value, HandleTxCompleteValue, HandleTxCompleteResult, InteractiveTxConstructor,
3535
InteractiveTxConstructorArgs, InteractiveTxMessageSend, InteractiveTxSigningSession, InteractiveTxMessageSendResult,
3636
OutputOwned, SharedOwnedOutput, TX_COMMON_FIELDS_WEIGHT,
3737
};
@@ -2270,7 +2270,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22702270
};
22712271

22722272
// Optionally add change output
2273-
if let Some(change_value) = need_to_add_funding_change_output(
2273+
if let Some(change_value) = calculate_change_output_value(
22742274
self.context.is_outbound(), self.dual_funding_context.our_funding_satoshis,
22752275
&funding_inputs_prev_outputs, &funding_outputs,
22762276
self.dual_funding_context.funding_feerate_sat_per_1000_weight,
@@ -2280,8 +2280,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22802280
|err| APIError::APIMisuseError {
22812281
err: format!("Failed to get change script as new destination script, {:?}", err),
22822282
})?;
2283-
let _res = add_funding_change_output(
2284-
change_value, change_script, &mut funding_outputs, self.dual_funding_context.funding_feerate_sat_per_1000_weight);
2283+
add_funding_change_output(change_value, change_script,
2284+
&mut funding_outputs, self.dual_funding_context.funding_feerate_sat_per_1000_weight);
22852285
}
22862286

22872287
let constructor_args = InteractiveTxConstructorArgs {
@@ -4734,7 +4734,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
47344734
fn add_funding_change_output(
47354735
change_value: u64, change_script: ScriptBuf,
47364736
funding_outputs: &mut Vec<OutputOwned>, funding_feerate_sat_per_1000_weight: u32,
4737-
) -> TxOut {
4737+
) {
47384738
let mut change_output = TxOut {
47394739
value: Amount::from_sat(change_value),
47404740
script_pubkey: change_script,
@@ -4743,7 +4743,6 @@ fn add_funding_change_output(
47434743
let change_output_fee = fee_for_weight(funding_feerate_sat_per_1000_weight, change_output_weight);
47444744
change_output.value = Amount::from_sat(change_value.saturating_sub(change_output_fee));
47454745
funding_outputs.push(OutputOwned::Single(change_output.clone()));
4746-
change_output
47474746
}
47484747

47494748
/// Estimate our part of the fee of the new funding transaction.

lightning/src/ln/interactivetxs.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,8 +1667,10 @@ impl InteractiveTxConstructor {
16671667
/// Determine whether a change output should be added or not, and if so, of what size,
16681668
/// considering our given inputs, outputs, and intended contribution.
16691669
/// Computes and takes into account fees.
1670+
/// Return value is the value computed for the change output (in satoshis),
1671+
/// or None if a change is not needed/possible.
16701672
#[allow(dead_code)] // TODO(dual_funding): Remove once begin_interactive_funding_tx_construction() is used
1671-
pub(super) fn need_to_add_funding_change_output(
1673+
pub(super) fn calculate_change_output_value(
16721674
is_initiator: bool, our_contribution: u64, funding_inputs_prev_outputs: &Vec<TxOut>,
16731675
funding_outputs: &Vec<OutputOwned>, funding_feerate_sat_per_1000_weight: u32,
16741676
holder_dust_limit_satoshis: u64,
@@ -1709,7 +1711,7 @@ mod tests {
17091711
use crate::chain::chaininterface::{fee_for_weight, FEERATE_FLOOR_SATS_PER_KW};
17101712
use crate::ln::channel::TOTAL_BITCOIN_SUPPLY_SATOSHIS;
17111713
use crate::ln::interactivetxs::{
1712-
generate_holder_serial_id, need_to_add_funding_change_output, AbortReason,
1714+
calculate_change_output_value, generate_holder_serial_id, AbortReason,
17131715
HandleTxCompleteValue, InteractiveTxConstructor, InteractiveTxConstructorArgs,
17141716
InteractiveTxMessageSend, MAX_INPUTS_OUTPUTS_COUNT, MAX_RECEIVED_TX_ADD_INPUT_COUNT,
17151717
MAX_RECEIVED_TX_ADD_OUTPUT_COUNT,
@@ -2639,7 +2641,7 @@ mod tests {
26392641
}
26402642

26412643
#[test]
2642-
fn test_need_to_add_funding_change_output_open() {
2644+
fn test_calculate_change_output_value_open() {
26432645
let input_prevouts = vec![
26442646
TxOut { value: Amount::from_sat(70_000), script_pubkey: ScriptBuf::new() },
26452647
TxOut { value: Amount::from_sat(60_000), script_pubkey: ScriptBuf::new() },
@@ -2655,7 +2657,7 @@ mod tests {
26552657
let common_fees = 126;
26562658
{
26572659
// There is leftover for change
2658-
let res = need_to_add_funding_change_output(
2660+
let res = calculate_change_output_value(
26592661
true,
26602662
our_contributed,
26612663
&input_prevouts,
@@ -2667,7 +2669,7 @@ mod tests {
26672669
}
26682670
{
26692671
// There is leftover for change, without common fees
2670-
let res = need_to_add_funding_change_output(
2672+
let res = calculate_change_output_value(
26712673
false,
26722674
our_contributed,
26732675
&input_prevouts,
@@ -2679,7 +2681,7 @@ mod tests {
26792681
}
26802682
{
26812683
// Larger fee, smaller change
2682-
let res = need_to_add_funding_change_output(
2684+
let res = calculate_change_output_value(
26832685
true,
26842686
our_contributed,
26852687
&input_prevouts,
@@ -2691,7 +2693,7 @@ mod tests {
26912693
}
26922694
{
26932695
// Insufficient inputs, no leftover
2694-
let res = need_to_add_funding_change_output(
2696+
let res = calculate_change_output_value(
26952697
false,
26962698
130_000,
26972699
&input_prevouts,
@@ -2703,7 +2705,7 @@ mod tests {
27032705
}
27042706
{
27052707
// Very small leftover
2706-
let res = need_to_add_funding_change_output(
2708+
let res = calculate_change_output_value(
27072709
false,
27082710
128_100,
27092711
&input_prevouts,
@@ -2715,7 +2717,7 @@ mod tests {
27152717
}
27162718
{
27172719
// Small leftover, but not dust
2718-
let res = need_to_add_funding_change_output(
2720+
let res = calculate_change_output_value(
27192721
false,
27202722
128_100,
27212723
&input_prevouts,
@@ -2728,7 +2730,7 @@ mod tests {
27282730
}
27292731

27302732
#[test]
2731-
fn test_need_to_add_funding_change_output_splice() {
2733+
fn test_calculate_change_output_value_splice() {
27322734
let input_prevouts = vec![
27332735
TxOut { value: Amount::from_sat(70_000), script_pubkey: ScriptBuf::new() },
27342736
TxOut { value: Amount::from_sat(60_000), script_pubkey: ScriptBuf::new() },
@@ -2744,7 +2746,7 @@ mod tests {
27442746
let common_fees = 126;
27452747
{
27462748
// There is leftover for change
2747-
let res = need_to_add_funding_change_output(
2749+
let res = calculate_change_output_value(
27482750
true,
27492751
our_contributed,
27502752
&input_prevouts,
@@ -2756,7 +2758,7 @@ mod tests {
27562758
}
27572759
{
27582760
// Very small leftover
2759-
let res = need_to_add_funding_change_output(
2761+
let res = calculate_change_output_value(
27602762
false,
27612763
128_100,
27622764
&input_prevouts,
@@ -2768,7 +2770,7 @@ mod tests {
27682770
}
27692771
{
27702772
// Small leftover, but not dust
2771-
let res = need_to_add_funding_change_output(
2773+
let res = calculate_change_output_value(
27722774
false,
27732775
128_100,
27742776
&input_prevouts,

0 commit comments

Comments
 (0)