Skip to content

Commit bceb683

Browse files
committed
Add requested changes
1 parent 3386f91 commit bceb683

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/wallet/coin_selection.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl CoinSelectionResult {
167167
/// that output in the future.
168168
/// > change_cost = current_fee_rate * change_output_size + long_term_feerate * change_spend_size
169169
///
170-
/// Excess happens when there is not change, and the surplus of coins is spend as part of the fees
170+
/// Excess happens when there is no change, and the surplus of coins is spend as part of the fees
171171
/// to the miner:
172172
/// > excess = tx_total_value - tx_fees - target
173173
///
@@ -181,7 +181,7 @@ impl CoinSelectionResult {
181181
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
182182
pub struct Waste(pub i64);
183183

184-
const LONG_TERM_FEE_RATE: FeeRate = FeeRate::from_sat_per_vb(10.0);
184+
const LONG_TERM_FEE_RATE: FeeRate = FeeRate::from_sat_per_vb(5.0);
185185

186186
impl Waste {
187187
/// Calculate the amount of waste for the given coin selection
@@ -1507,16 +1507,19 @@ mod test {
15071507
.map(|u| OutputGroup::new(u, fee_rate))
15081508
.collect();
15091509

1510-
let size_of_change = 31;
1511-
let cost_of_change: u64 = (size_of_change as f32 * fee_rate.as_sat_vb()) as u64;
1510+
let change_out_size = 31_f32;
1511+
let change_in_size = 68_f32;
1512+
let cost_of_change: u64 = (change_out_size * fee_rate.as_sat_vb()
1513+
- change_in_size * LONG_TERM_FEE_RATE.as_sat_vb())
1514+
as u64;
15121515

15131516
let utxo_fee_diff: i64 = utxos.iter().fold(0, |acc, utxo| {
1514-
let fee_rate: i64 = utxo.fee as i64;
1517+
let fee: i64 = utxo.fee as i64;
15151518
let long_term_fee: i64 = LONG_TERM_FEE_RATE
15161519
.fee_wu(TXIN_BASE_WEIGHT + utxo.weighted_utxo.satisfaction_weight)
15171520
as i64;
15181521

1519-
acc + fee_rate - long_term_fee
1522+
acc + fee - long_term_fee
15201523
});
15211524

15221525
// Waste with change is the change cost and difference between fee and long term fee
@@ -1541,12 +1544,12 @@ mod test {
15411544
let utxos_fee: u64 = utxos.clone().iter().fold(0, |acc, utxo| acc + utxo.fee);
15421545

15431546
let utxo_fee_diff: i64 = utxos.iter().fold(0, |acc, utxo| {
1544-
let fee_rate: i64 = utxo.fee as i64;
1547+
let fee: i64 = utxo.fee as i64;
15451548
let long_term_fee: i64 = LONG_TERM_FEE_RATE
15461549
.fee_wu(TXIN_BASE_WEIGHT + utxo.weighted_utxo.satisfaction_weight)
15471550
as i64;
15481551

1549-
acc + fee_rate - long_term_fee
1552+
acc + fee - long_term_fee
15501553
});
15511554

15521555
let excess = available_value - utxos_fee - amount_needed;
@@ -1585,12 +1588,12 @@ mod test {
15851588
let utxos_fee: u64 = utxos.clone().iter().fold(0, |acc, utxo| acc + utxo.fee);
15861589

15871590
let utxo_fee_diff: i64 = utxos.iter().fold(0, |acc, utxo| {
1588-
let fee_rate: i64 = utxo.fee as i64;
1591+
let fee: i64 = utxo.fee as i64;
15891592
let long_term_fee: i64 = LONG_TERM_FEE_RATE
15901593
.fee_wu(TXIN_BASE_WEIGHT + utxo.weighted_utxo.satisfaction_weight)
15911594
as i64;
15921595

1593-
acc + fee_rate - long_term_fee
1596+
acc + fee - long_term_fee
15941597
});
15951598

15961599
let excess = available_value - utxos_fee - amount_needed;
@@ -1603,7 +1606,7 @@ mod test {
16031606

16041607
#[test]
16051608
fn test_calculate_waste_with_no_timing_cost_and_no_creation_cost() {
1606-
let fee_rate = FeeRate::from_sat_per_vb(10.0);
1609+
let fee_rate = LONG_TERM_FEE_RATE;
16071610
let utxo_values = vec![200_000_000];
16081611
let selected = generate_utxos_of_values(utxo_values.clone());
16091612

0 commit comments

Comments
 (0)