use chain::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER};
use chain::keysinterface::{Sign, KeysInterface};
use chain::package::PackageTemplate;
-use chain::package;
use util::logger::Logger;
use util::ser::{Readable, ReadableArgs, Writer, Writeable, VecWriter};
use util::byte_utils;
let amt = cached_request.package_amount();
if cached_request.is_malleable() {
let predicted_weight = cached_request.package_weight(&self.destination_script);
- if let Some((output_value, new_feerate)) = package::compute_output_value(predicted_weight, amt, cached_request.feerate(), fee_estimator, logger) {
+ if let Some((output_value, new_feerate)) = cached_request.compute_package_output(predicted_weight, amt, fee_estimator, logger) {
assert!(new_feerate != 0);
let transaction = cached_request.finalize_package(self, output_value, self.destination_script.clone(), logger).unwrap();
pub(crate) fn aggregable(&self) -> bool {
self.aggregable
}
- pub(crate) fn feerate(&self) -> u64 {
- self.feerate_previous
- }
pub(crate) fn set_feerate(&mut self, new_feerate: u64) {
self.feerate_previous = new_feerate;
}
}
current_height + LOW_FREQUENCY_BUMP_INTERVAL
}
+ /// Returns value in satoshis to be included as package outgoing output amount and feerate with which package finalization should be done.
+ pub(crate) fn compute_package_output<F: Deref, L: Deref>(&self, predicted_weight: usize, input_amounts: u64, fee_estimator: &F, logger: &L) -> Option<(u64, u64)>
+ where F::Target: FeeEstimator,
+ L::Target: Logger,
+ {
+ // If old feerate is 0, first iteration of this claim, use normal fee calculation
+ if self.feerate_previous != 0 {
+ if let Some((new_fee, feerate)) = feerate_bump(predicted_weight, input_amounts, self.feerate_previous, fee_estimator, logger) {
+ // If new computed fee is superior at the whole claimable amount burn all in fees
+ if new_fee > input_amounts {
+ return Some((0, feerate));
+ } else {
+ return Some((input_amounts - new_fee, feerate));
+ }
+ }
+ } else {
+ if let Some((new_fee, feerate)) = compute_fee_from_spent_amounts(input_amounts, predicted_weight, fee_estimator, logger) {
+ return Some((input_amounts - new_fee, feerate));
+ }
+ }
+ None
+ }
pub (crate) fn build_package(txid: Txid, vout: u32, input_solving_data: PackageSolvingData, soonest_conf_deadline: u32, aggregable: bool, height_original: u32) -> Self {
let malleability = match input_solving_data {
PackageSolvingData::RevokedOutput(..) => { PackageMalleability::Malleable },
};
Some((new_fee, new_fee * 1000 / (predicted_weight as u64)))
}
-
-/// Deduce a new proposed fee from the claiming transaction output value.
-/// If the new proposed fee is superior to the consumed outpoint's value, burn everything in miner's
-/// fee to deter counterparties attacker.
-pub(crate) fn compute_output_value<F: Deref, L: Deref>(predicted_weight: usize, input_amounts: u64, previous_feerate: u64, fee_estimator: &F, logger: &L) -> Option<(u64, u64)>
- where F::Target: FeeEstimator,
- L::Target: Logger,
-{
- // If old feerate is 0, first iteration of this claim, use normal fee calculation
- if previous_feerate != 0 {
- if let Some((new_fee, feerate)) = feerate_bump(predicted_weight, input_amounts, previous_feerate, fee_estimator, logger) {
- // If new computed fee is superior at the whole claimable amount burn all in fees
- if new_fee > input_amounts {
- return Some((0, feerate));
- } else {
- return Some((input_amounts - new_fee, feerate));
- }
- }
- } else {
- if let Some((new_fee, feerate)) = compute_fee_from_spent_amounts(input_amounts, predicted_weight, fee_estimator, logger) {
- return Some((input_amounts - new_fee, feerate));
- }
- }
- None
-}
-