@@ -876,7 +876,7 @@ impl PackageTemplate {
876876
877877 locktime
878878 }
879- pub ( crate ) fn package_weight ( & self , destination_script : & Script ) -> usize {
879+ pub ( crate ) fn package_weight ( & self , destination_script : & Script ) -> u64 {
880880 let mut inputs_weight = 0 ;
881881 let mut witnesses_weight = 2 ; // count segwit flags
882882 for ( _, outp) in self . inputs . iter ( ) {
@@ -888,7 +888,7 @@ impl PackageTemplate {
888888 let transaction_weight = 10 * WITNESS_SCALE_FACTOR ;
889889 // value: 8 bytes ; var_int: 1 byte ; pk_script: `destination_script.len()`
890890 let output_weight = ( 8 + 1 + destination_script. len ( ) ) * WITNESS_SCALE_FACTOR ;
891- inputs_weight + witnesses_weight + transaction_weight + output_weight
891+ ( inputs_weight + witnesses_weight + transaction_weight + output_weight) as u64
892892 }
893893 pub ( crate ) fn construct_malleable_package_with_external_funding < Signer : WriteableEcdsaChannelSigner > (
894894 & self , onchain_handler : & mut OnchainTxHandler < Signer > ,
@@ -963,7 +963,7 @@ impl PackageTemplate {
963963 /// which was used to generate the value. Will not return less than `dust_limit_sats` for the
964964 /// value.
965965 pub ( crate ) fn compute_package_output < F : Deref , L : Deref > (
966- & self , predicted_weight : usize , dust_limit_sats : u64 , force_feerate_bump : bool ,
966+ & self , predicted_weight : u64 , dust_limit_sats : u64 , force_feerate_bump : bool ,
967967 fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & L ,
968968 ) -> Option < ( u64 , u64 ) >
969969 where
@@ -1111,21 +1111,21 @@ impl Readable for PackageTemplate {
11111111///
11121112/// [`OnChainSweep`]: crate::chain::chaininterface::ConfirmationTarget::OnChainSweep
11131113/// [`FEERATE_FLOOR_SATS_PER_KW`]: crate::chain::chaininterface::MIN_RELAY_FEE_SAT_PER_1000_WEIGHT
1114- fn compute_fee_from_spent_amounts < F : Deref , L : Deref > ( input_amounts : u64 , predicted_weight : usize , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & L ) -> Option < ( u64 , u64 ) >
1114+ fn compute_fee_from_spent_amounts < F : Deref , L : Deref > ( input_amounts : u64 , predicted_weight : u64 , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & L ) -> Option < ( u64 , u64 ) >
11151115 where F :: Target : FeeEstimator ,
11161116 L :: Target : Logger ,
11171117{
11181118 let sweep_feerate = fee_estimator. bounded_sat_per_1000_weight ( ConfirmationTarget :: OnChainSweep ) ;
1119- let fee_rate = cmp:: min ( sweep_feerate, compute_feerate_sat_per_1000_weight ( input_amounts / 2 , predicted_weight as u64 ) ) as u64 ;
1120- let fee = fee_rate * ( predicted_weight as u64 ) / 1000 ;
1119+ let fee_rate = cmp:: min ( sweep_feerate, compute_feerate_sat_per_1000_weight ( input_amounts / 2 , predicted_weight) ) ;
1120+ let fee = fee_rate as u64 * ( predicted_weight) / 1000 ;
11211121
11221122 // if the fee rate is below the floor, we don't sweep
1123- if fee_rate < FEERATE_FLOOR_SATS_PER_KW as u64 {
1123+ if fee_rate < FEERATE_FLOOR_SATS_PER_KW {
11241124 log_error ! ( logger, "Failed to generate an on-chain tx with fee ({} sat/kw) was less than the floor ({} sat/kw)" ,
11251125 fee_rate, FEERATE_FLOOR_SATS_PER_KW ) ;
11261126 None
11271127 } else {
1128- Some ( ( fee, fee_rate) )
1128+ Some ( ( fee, fee_rate as u64 ) )
11291129 }
11301130}
11311131
@@ -1136,7 +1136,7 @@ fn compute_fee_from_spent_amounts<F: Deref, L: Deref>(input_amounts: u64, predic
11361136/// verify that those bumping heuristics respect BIP125 rules 3) and 4) and if required adjust the
11371137/// new fee to meet the RBF policy requirement.
11381138fn feerate_bump < F : Deref , L : Deref > (
1139- predicted_weight : usize , input_amounts : u64 , previous_feerate : u64 , force_feerate_bump : bool ,
1139+ predicted_weight : u64 , input_amounts : u64 , previous_feerate : u64 , force_feerate_bump : bool ,
11401140 fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & L ,
11411141) -> Option < ( u64 , u64 ) >
11421142where
@@ -1148,12 +1148,12 @@ where
11481148 if new_feerate > previous_feerate {
11491149 ( new_fee, new_feerate)
11501150 } else if !force_feerate_bump {
1151- let previous_fee = previous_feerate * ( predicted_weight as u64 ) / 1000 ;
1151+ let previous_fee = previous_feerate * predicted_weight / 1000 ;
11521152 ( previous_fee, previous_feerate)
11531153 } else {
11541154 // ...else just increase the previous feerate by 25% (because that's a nice number)
11551155 let bumped_feerate = previous_feerate + ( previous_feerate / 4 ) ;
1156- let bumped_fee = bumped_feerate * ( predicted_weight as u64 ) / 1000 ;
1156+ let bumped_fee = bumped_feerate * predicted_weight / 1000 ;
11571157 if input_amounts <= bumped_fee {
11581158 log_warn ! ( logger, "Can't 25% bump new claiming tx, amount {} is too small" , input_amounts) ;
11591159 return None ;
@@ -1172,8 +1172,8 @@ where
11721172 return Some ( ( new_fee, new_feerate) ) ;
11731173 }
11741174
1175- let previous_fee = previous_feerate * ( predicted_weight as u64 ) / 1000 ;
1176- let min_relay_fee = MIN_RELAY_FEE_SAT_PER_1000_WEIGHT * ( predicted_weight as u64 ) / 1000 ;
1175+ let previous_fee = previous_feerate * predicted_weight / 1000 ;
1176+ let min_relay_fee = MIN_RELAY_FEE_SAT_PER_1000_WEIGHT * predicted_weight / 1000 ;
11771177 // BIP 125 Opt-in Full Replace-by-Fee Signaling
11781178 // * 3. The replacement transaction pays an absolute fee of at least the sum paid by the original transactions.
11791179 // * 4. The replacement transaction must also pay for its own bandwidth at or above the rate set by the node's minimum relay fee setting.
@@ -1182,7 +1182,7 @@ where
11821182 } else {
11831183 new_fee
11841184 } ;
1185- Some ( ( new_fee, new_fee * 1000 / ( predicted_weight as u64 ) ) )
1185+ Some ( ( new_fee, new_fee * 1000 / predicted_weight) )
11861186}
11871187
11881188#[ cfg( test) ]
@@ -1402,27 +1402,27 @@ mod tests {
14021402 let secp_ctx = Secp256k1 :: new ( ) ;
14031403
14041404 // (nVersion (4) + nLocktime (4) + count_tx_in (1) + prevout (36) + sequence (4) + script_length (1) + count_tx_out (1) + value (8) + var_int (1)) * WITNESS_SCALE_FACTOR + witness marker (2)
1405- let weight_sans_output = ( 4 + 4 + 1 + 36 + 4 + 1 + 1 + 8 + 1 ) * WITNESS_SCALE_FACTOR + 2 ;
1405+ let weight_sans_output = ( 4 + 4 + 1 + 36 + 4 + 1 + 1 + 8 + 1 ) * WITNESS_SCALE_FACTOR as u64 + 2 ;
14061406
14071407 {
14081408 let revk_outp = dumb_revk_output ! ( secp_ctx, false ) ;
14091409 let package = PackageTemplate :: build_package ( txid, 0 , revk_outp, 0 , 100 ) ;
1410- assert_eq ! ( package. package_weight( & Script :: new( ) ) , weight_sans_output + WEIGHT_REVOKED_OUTPUT as usize ) ;
1410+ assert_eq ! ( package. package_weight( & Script :: new( ) ) , weight_sans_output + WEIGHT_REVOKED_OUTPUT ) ;
14111411 }
14121412
14131413 {
14141414 for channel_type_features in [ ChannelTypeFeatures :: only_static_remote_key ( ) , ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) ] . iter ( ) {
14151415 let counterparty_outp = dumb_counterparty_output ! ( secp_ctx, 1_000_000 , channel_type_features. clone( ) ) ;
14161416 let package = PackageTemplate :: build_package ( txid, 0 , counterparty_outp, 1000 , 100 ) ;
1417- assert_eq ! ( package. package_weight( & Script :: new( ) ) , weight_sans_output + weight_received_htlc( channel_type_features) as usize ) ;
1417+ assert_eq ! ( package. package_weight( & Script :: new( ) ) , weight_sans_output + weight_received_htlc( channel_type_features) ) ;
14181418 }
14191419 }
14201420
14211421 {
14221422 for channel_type_features in [ ChannelTypeFeatures :: only_static_remote_key ( ) , ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) ] . iter ( ) {
14231423 let counterparty_outp = dumb_counterparty_offered_output ! ( secp_ctx, 1_000_000 , channel_type_features. clone( ) ) ;
14241424 let package = PackageTemplate :: build_package ( txid, 0 , counterparty_outp, 1000 , 100 ) ;
1425- assert_eq ! ( package. package_weight( & Script :: new( ) ) , weight_sans_output + weight_offered_htlc( channel_type_features) as usize ) ;
1425+ assert_eq ! ( package. package_weight( & Script :: new( ) ) , weight_sans_output + weight_offered_htlc( channel_type_features) ) ;
14261426 }
14271427 }
14281428 }
0 commit comments