+
+ let expected_package_fee = fee_for_weight(package_target_feerate_sat_per_1000_weight,
+ signed_tx_weight + commitment_tx.weight() as u64);
+ let package_fee = total_input_amount -
+ anchor_tx.output.iter().map(|output| output.value).sum::<u64>();
+ // Our fee should be within a 5% error margin of the expected fee based on the
+ // feerate and transaction weight and we should never pay less than required.
+ let fee_error_margin = expected_package_fee * 5 / 100;
+ assert!(package_fee >= expected_package_fee &&
+ package_fee - fee_error_margin <= expected_package_fee);