From 43a51a1ec3b260744a46ddfdba1d2d0e7e4a3992 Mon Sep 17 00:00:00 2001 From: Murch Date: Mon, 26 Oct 2020 14:08:57 -0400 Subject: [PATCH 1/3] Rename must_use_utxos to required_utxos --- src/wallet/coin_selection.rs | 12 ++++++------ src/wallet/mod.rs | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/wallet/coin_selection.rs b/src/wallet/coin_selection.rs index 7de2b0a2..bd96d345 100644 --- a/src/wallet/coin_selection.rs +++ b/src/wallet/coin_selection.rs @@ -53,7 +53,7 @@ //! fn coin_select( //! &self, //! database: &D, -//! must_use_utxos: Vec<(UTXO, usize)>, +//! required_utxos: Vec<(UTXO, usize)>, //! may_use_utxos: Vec<(UTXO, usize)>, //! fee_rate: FeeRate, //! amount_needed: u64, @@ -61,7 +61,7 @@ //! ) -> Result { //! let mut selected_amount = 0; //! let mut additional_weight = 0; -//! let all_utxos_selected = must_use_utxos +//! let all_utxos_selected = required_utxos //! .into_iter().chain(may_use_utxos) //! .scan((&mut selected_amount, &mut additional_weight), |(selected_amount, additional_weight), (utxo, weight)| { //! let txin = TxIn { @@ -139,7 +139,7 @@ pub trait CoinSelectionAlgorithm: std::fmt::Debug { /// /// - `database`: a reference to the wallet's database that can be used to lookup additional /// details for a specific UTXO - /// - `must_use_utxos`: the utxos that must be spent regardless of `amount_needed` with their + /// - `required_utxos`: the utxos that must be spent regardless of `amount_needed` with their /// weight cost /// - `may_be_spent`: the utxos that may be spent to satisfy `amount_needed` with their weight /// cost @@ -150,7 +150,7 @@ pub trait CoinSelectionAlgorithm: std::fmt::Debug { fn coin_select( &self, database: &D, - must_use_utxos: Vec<(UTXO, usize)>, + required_utxos: Vec<(UTXO, usize)>, may_use_utxos: Vec<(UTXO, usize)>, fee_rate: FeeRate, amount_needed: u64, @@ -169,7 +169,7 @@ impl CoinSelectionAlgorithm for DumbCoinSelection { fn coin_select( &self, _database: &D, - must_use_utxos: Vec<(UTXO, usize)>, + required_utxos: Vec<(UTXO, usize)>, mut may_use_utxos: Vec<(UTXO, usize)>, fee_rate: FeeRate, amount_needed: u64, @@ -188,7 +188,7 @@ impl CoinSelectionAlgorithm for DumbCoinSelection { // smallest to largest, before being reversed with `.rev()`. let utxos = { may_use_utxos.sort_unstable_by_key(|(utxo, _)| utxo.txout.value); - must_use_utxos + required_utxos .into_iter() .map(|utxo| (true, utxo)) .chain(may_use_utxos.into_iter().rev().map(|utxo| (false, utxo))) diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 845da0f0..0ea263b1 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -348,7 +348,7 @@ where )); } - let (must_use_utxos, may_use_utxos) = self.get_must_may_use_utxos( + let (required_utxos, may_use_utxos) = self.get_must_may_use_utxos( builder.change_policy, &builder.unspendable, &builder.utxos, @@ -363,7 +363,7 @@ where mut fee_amount, } = builder.coin_selection.coin_select( self.database.borrow().deref(), - must_use_utxos, + required_utxos, may_use_utxos, fee_rate, outgoing, @@ -604,7 +604,7 @@ where .cloned() .collect::>(); - let (mut must_use_utxos, may_use_utxos) = self.get_must_may_use_utxos( + let (mut required_utxos, may_use_utxos) = self.get_must_may_use_utxos( builder.change_policy, &builder.unspendable, &builder_extra_utxos[..], @@ -613,7 +613,7 @@ where true, // we only want confirmed transactions for RBF )?; - must_use_utxos.append(&mut original_utxos); + required_utxos.append(&mut original_utxos); let amount_needed = tx.output.iter().fold(0, |acc, out| acc + out.value); let (new_feerate, initial_fee) = match builder @@ -645,7 +645,7 @@ where fee_amount, } = builder.coin_selection.coin_select( self.database.borrow().deref(), - must_use_utxos, + required_utxos, may_use_utxos, new_feerate, amount_needed, From 84aee3baab26e2e88b3b7455930e701bac661a7e Mon Sep 17 00:00:00 2001 From: Murch Date: Mon, 26 Oct 2020 14:12:46 -0400 Subject: [PATCH 2/3] Rename may_use_utxos to optional_uxtos --- src/wallet/coin_selection.rs | 20 ++++++++++---------- src/wallet/mod.rs | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/wallet/coin_selection.rs b/src/wallet/coin_selection.rs index bd96d345..3f70a3e8 100644 --- a/src/wallet/coin_selection.rs +++ b/src/wallet/coin_selection.rs @@ -54,7 +54,7 @@ //! &self, //! database: &D, //! required_utxos: Vec<(UTXO, usize)>, -//! may_use_utxos: Vec<(UTXO, usize)>, +//! optional_utxos: Vec<(UTXO, usize)>, //! fee_rate: FeeRate, //! amount_needed: u64, //! fee_amount: f32, @@ -62,7 +62,7 @@ //! let mut selected_amount = 0; //! let mut additional_weight = 0; //! let all_utxos_selected = required_utxos -//! .into_iter().chain(may_use_utxos) +//! .into_iter().chain(optional_utxos) //! .scan((&mut selected_amount, &mut additional_weight), |(selected_amount, additional_weight), (utxo, weight)| { //! let txin = TxIn { //! previous_output: utxo.outpoint, @@ -141,8 +141,8 @@ pub trait CoinSelectionAlgorithm: std::fmt::Debug { /// details for a specific UTXO /// - `required_utxos`: the utxos that must be spent regardless of `amount_needed` with their /// weight cost - /// - `may_be_spent`: the utxos that may be spent to satisfy `amount_needed` with their weight - /// cost + /// - `optional_utxos`: the remaining available utxos to satisfy `amount_needed` with their + /// weight cost /// - `fee_rate`: fee rate to use /// - `amount_needed`: the amount in satoshi to select /// - `fee_amount`: the amount of fees in satoshi already accumulated from adding outputs and @@ -151,7 +151,7 @@ pub trait CoinSelectionAlgorithm: std::fmt::Debug { &self, database: &D, required_utxos: Vec<(UTXO, usize)>, - may_use_utxos: Vec<(UTXO, usize)>, + optional_utxos: Vec<(UTXO, usize)>, fee_rate: FeeRate, amount_needed: u64, fee_amount: f32, @@ -170,7 +170,7 @@ impl CoinSelectionAlgorithm for DumbCoinSelection { &self, _database: &D, required_utxos: Vec<(UTXO, usize)>, - mut may_use_utxos: Vec<(UTXO, usize)>, + mut optional_utxos: Vec<(UTXO, usize)>, fee_rate: FeeRate, amount_needed: u64, mut fee_amount: f32, @@ -184,14 +184,14 @@ impl CoinSelectionAlgorithm for DumbCoinSelection { fee_rate ); - // We put the "must_use" UTXOs first and make sure the "may_use" are sorted, initially - // smallest to largest, before being reversed with `.rev()`. + // We put the "required UTXOs" first and make sure the optional UTXOs are sorted, + // initially smallest to largest, before being reversed with `.rev()`. let utxos = { - may_use_utxos.sort_unstable_by_key(|(utxo, _)| utxo.txout.value); + optional_utxos.sort_unstable_by_key(|(utxo, _)| utxo.txout.value); required_utxos .into_iter() .map(|utxo| (true, utxo)) - .chain(may_use_utxos.into_iter().rev().map(|utxo| (false, utxo))) + .chain(optional_utxos.into_iter().rev().map(|utxo| (false, utxo))) }; // Keep including inputs until we've got enough. diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 0ea263b1..3106414d 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -348,7 +348,7 @@ where )); } - let (required_utxos, may_use_utxos) = self.get_must_may_use_utxos( + let (required_utxos, optional_utxos) = self.get_must_may_use_utxos( builder.change_policy, &builder.unspendable, &builder.utxos, @@ -364,7 +364,7 @@ where } = builder.coin_selection.coin_select( self.database.borrow().deref(), required_utxos, - may_use_utxos, + optional_utxos, fee_rate, outgoing, fee_amount, @@ -604,7 +604,7 @@ where .cloned() .collect::>(); - let (mut required_utxos, may_use_utxos) = self.get_must_may_use_utxos( + let (mut required_utxos, optional_utxos) = self.get_must_may_use_utxos( builder.change_policy, &builder.unspendable, &builder_extra_utxos[..], @@ -646,7 +646,7 @@ where } = builder.coin_selection.coin_select( self.database.borrow().deref(), required_utxos, - may_use_utxos, + optional_utxos, new_feerate, amount_needed, initial_fee, From 457e70e70f2c05ddeaa8d107890b082b9ad6ec0a Mon Sep 17 00:00:00 2001 From: Murch Date: Mon, 26 Oct 2020 14:23:46 -0400 Subject: [PATCH 3/3] Rename get_must_may_use_utxos to preselect_utxos --- src/wallet/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 3106414d..daff0261 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -348,7 +348,7 @@ where )); } - let (required_utxos, optional_utxos) = self.get_must_may_use_utxos( + let (required_utxos, optional_utxos) = self.preselect_utxos( builder.change_policy, &builder.unspendable, &builder.utxos, @@ -604,7 +604,7 @@ where .cloned() .collect::>(); - let (mut required_utxos, optional_utxos) = self.get_must_may_use_utxos( + let (mut required_utxos, optional_utxos) = self.preselect_utxos( builder.change_policy, &builder.unspendable, &builder_extra_utxos[..], @@ -985,7 +985,7 @@ where /// Given the options returns the list of utxos that must be used to form the /// transaction and any further that may be used if needed. #[allow(clippy::type_complexity)] - fn get_must_may_use_utxos( + fn preselect_utxos( &self, change_policy: tx_builder::ChangeSpendPolicy, unspendable: &HashSet,