-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c650306 fix: `CoinSelector::implied_fee` (志宇) 4d0ae4c docs: fix typos (志宇) 2e26aa5 fix: rm `Drain::none` method (志宇) 8eb582b [lowest-fee] ignore failure when selection is not possible (LLFourn) 064996c [lowest-fee] Fix off by one in test (LLFourn) 956685a [changeless] Revert number of candidates (LLFourn) c6f0682 Remove typo in lowest_fee comment (LLFourn) 76e67a3 Move ChangePolicy to drain.rs (LLFourn) 7e82c3f Remove base_weight, put weight in Target (LLFourn) Pull request description: Fixes #1 On top of #19 - CoinSelector no longer tracks anything but input weight - Previously the value of the target outputs was in `Target` but the weights were accounted for in CoinSelector. Now they're in all in target. - This allows us to actually figure out how many outputs there are and therefore the actual weight of the transaction accounting for the varint for the number of outputs. This wasn't what the issue had in mind but it was easier to take the `base_weight` out of `CoinSelector` and put it in `Target` rather than put `Target` in `CoinSelector`. Getting rid of `base_weight` is a more crucial change than expected because rust bitcoin changed what `Transaction::weight` returns for empty output transactions recently so using it to determine `base_weight` will get different answers between versions (this breaks our weight tests but this PR will fix it I think if we uprade dev deps). We only need to know the total weight of the outputs and how many there are now to get the right answers for weight. ACKs for top commit: evanlinjin: ACK c650306 Tree-SHA512: bd2d6bba15a172b56451d13a9560b6221a6f005417857e1cf7f0cd7022cebd0c2e4d6ff78dac9b99690771297351f90eb3fea26f85aa34a2841c91cfe0d73f9c
- Loading branch information
Showing
19 changed files
with
516 additions
and
1,301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1 @@ | ||
//! This module contains a collection of change policies. | ||
//! | ||
//! A change policy determines whether a given coin selection (presented by [`CoinSelector`]) should | ||
//! construct a transaction with a change output. A change policy is represented as a function of | ||
//! type `Fn(&CoinSelector, Target) -> Drain`. | ||
|
||
#[allow(unused)] // some bug in <= 1.48.0 sees this as unused when it isn't | ||
use crate::float::FloatExt; | ||
use crate::{DrainWeights, FeeRate}; | ||
|
||
/// Describes when a change output (although it could represent several) should be added that drains | ||
/// the excess in the coin selection. It includes the `drain_weights` to account for the cost of | ||
/// adding this outupt(s). | ||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub struct ChangePolicy { | ||
/// The minimum amount of excesss there needs to be add a change output. | ||
pub min_value: u64, | ||
/// The weights of the drain that would be added according to the policy. | ||
pub drain_weights: DrainWeights, | ||
} | ||
|
||
impl ChangePolicy { | ||
/// Construct a change policy that creates change when the change value is greater than | ||
/// `min_value`. | ||
pub fn min_value(drain_weights: DrainWeights, min_value: u64) -> Self { | ||
Self { | ||
drain_weights, | ||
min_value, | ||
} | ||
} | ||
|
||
/// Construct a change policy that creates change when it would reduce the transaction waste | ||
/// given that `min_value` is respected. | ||
pub fn min_value_and_waste( | ||
drain_weights: DrainWeights, | ||
min_value: u64, | ||
target_feerate: FeeRate, | ||
long_term_feerate: FeeRate, | ||
) -> Self { | ||
// The output waste of a changeless solution is the excess. | ||
let waste_with_change = drain_weights | ||
.waste(target_feerate, long_term_feerate) | ||
.ceil() as u64; | ||
|
||
Self { | ||
drain_weights, | ||
min_value: waste_with_change.max(min_value), | ||
} | ||
} | ||
} |
Oops, something went wrong.