@@ -167,7 +167,7 @@ impl CoinSelectionResult {
167
167
/// that output in the future.
168
168
/// > change_cost = current_fee_rate * change_output_size + long_term_feerate * change_spend_size
169
169
///
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
171
171
/// to the miner:
172
172
/// > excess = tx_total_value - tx_fees - target
173
173
///
@@ -181,7 +181,7 @@ impl CoinSelectionResult {
181
181
#[ derive( Debug , PartialEq , Eq , PartialOrd , Ord ) ]
182
182
pub struct Waste ( pub i64 ) ;
183
183
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) ;
185
185
186
186
impl Waste {
187
187
/// Calculate the amount of waste for the given coin selection
@@ -1507,16 +1507,19 @@ mod test {
1507
1507
. map ( |u| OutputGroup :: new ( u, fee_rate) )
1508
1508
. collect ( ) ;
1509
1509
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 ;
1512
1515
1513
1516
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 ;
1515
1518
let long_term_fee: i64 = LONG_TERM_FEE_RATE
1516
1519
. fee_wu ( TXIN_BASE_WEIGHT + utxo. weighted_utxo . satisfaction_weight )
1517
1520
as i64 ;
1518
1521
1519
- acc + fee_rate - long_term_fee
1522
+ acc + fee - long_term_fee
1520
1523
} ) ;
1521
1524
1522
1525
// Waste with change is the change cost and difference between fee and long term fee
@@ -1541,12 +1544,12 @@ mod test {
1541
1544
let utxos_fee: u64 = utxos. clone ( ) . iter ( ) . fold ( 0 , |acc, utxo| acc + utxo. fee ) ;
1542
1545
1543
1546
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 ;
1545
1548
let long_term_fee: i64 = LONG_TERM_FEE_RATE
1546
1549
. fee_wu ( TXIN_BASE_WEIGHT + utxo. weighted_utxo . satisfaction_weight )
1547
1550
as i64 ;
1548
1551
1549
- acc + fee_rate - long_term_fee
1552
+ acc + fee - long_term_fee
1550
1553
} ) ;
1551
1554
1552
1555
let excess = available_value - utxos_fee - amount_needed;
@@ -1585,12 +1588,12 @@ mod test {
1585
1588
let utxos_fee: u64 = utxos. clone ( ) . iter ( ) . fold ( 0 , |acc, utxo| acc + utxo. fee ) ;
1586
1589
1587
1590
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 ;
1589
1592
let long_term_fee: i64 = LONG_TERM_FEE_RATE
1590
1593
. fee_wu ( TXIN_BASE_WEIGHT + utxo. weighted_utxo . satisfaction_weight )
1591
1594
as i64 ;
1592
1595
1593
- acc + fee_rate - long_term_fee
1596
+ acc + fee - long_term_fee
1594
1597
} ) ;
1595
1598
1596
1599
let excess = available_value - utxos_fee - amount_needed;
@@ -1603,7 +1606,7 @@ mod test {
1603
1606
1604
1607
#[ test]
1605
1608
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 ;
1607
1610
let utxo_values = vec ! [ 200_000_000 ] ;
1608
1611
let selected = generate_utxos_of_values ( utxo_values. clone ( ) ) ;
1609
1612
0 commit comments