Coin selection cleanups (#607)

* coin selection (cleanup):
  - rename `selection_strategy: bool` and `default_strategy: bool`
  - use `selection_strategy_is_use_all` outside, and `use_all` inside wallet types (narrowly escaping rustfmt!)
This commit is contained in:
Simon B 2018-01-12 21:05:57 +01:00 committed by Ignotus Peverell
parent 8b2f9503c9
commit d28f37d5b3
2 changed files with 13 additions and 13 deletions

View file

@ -35,7 +35,7 @@ pub fn issue_send_tx(
minimum_confirmations: u64, minimum_confirmations: u64,
dest: String, dest: String,
max_outputs: usize, max_outputs: usize,
selection_strategy: bool, selection_strategy_is_use_all: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
checker::refresh_outputs(config, keychain)?; checker::refresh_outputs(config, keychain)?;
@ -53,7 +53,7 @@ pub fn issue_send_tx(
minimum_confirmations, minimum_confirmations,
lock_height, lock_height,
max_outputs, max_outputs,
selection_strategy, selection_strategy_is_use_all,
)?; )?;
/* /*
* -Sender picks random blinding factors for all outputs it participates in, computes total blinding excess xS * -Sender picks random blinding factors for all outputs it participates in, computes total blinding excess xS
@ -162,7 +162,7 @@ fn build_send_tx(
minimum_confirmations: u64, minimum_confirmations: u64,
lock_height: u64, lock_height: u64,
max_outputs: usize, max_outputs: usize,
default_strategy: bool, selection_strategy_is_use_all: bool,
) -> Result<(Transaction, BlindingFactor, Vec<OutputData>, Identifier), Error> { ) -> Result<(Transaction, BlindingFactor, Vec<OutputData>, Identifier), Error> {
let key_id = keychain.clone().root_key_id(); let key_id = keychain.clone().root_key_id();
@ -174,7 +174,7 @@ fn build_send_tx(
current_height, current_height,
minimum_confirmations, minimum_confirmations,
max_outputs, max_outputs,
default_strategy, selection_strategy_is_use_all,
) )
})?; })?;

View file

@ -529,7 +529,7 @@ impl WalletData {
current_height: u64, current_height: u64,
minimum_confirmations: u64, minimum_confirmations: u64,
max_outputs: usize, max_outputs: usize,
default_strategy: bool, select_all: bool,
) -> Vec<OutputData> { ) -> Vec<OutputData> {
// first find all eligible outputs based on number of confirmations // first find all eligible outputs based on number of confirmations
let mut eligible = self.outputs let mut eligible = self.outputs
@ -546,7 +546,7 @@ impl WalletData {
// use a sliding window to identify potential sets of possible outputs to spend // use a sliding window to identify potential sets of possible outputs to spend
// Case of amount > total amount of max_outputs(500): // Case of amount > total amount of max_outputs(500):
// The limit exists because by default, we always select as many inputs as possible in a transaction, // The limit exists because by default, we always select as many inputs as possible in a transaction,
// to reduce both the UTXO set and the fees. // to reduce both the UTXO set and the fees.
// But that only makes sense up to a point, hence the limit to avoid being too greedy. // But that only makes sense up to a point, hence the limit to avoid being too greedy.
// But if max_outputs(500) is actually not enought to cover the whole amount, // But if max_outputs(500) is actually not enought to cover the whole amount,
@ -554,8 +554,8 @@ impl WalletData {
// So the wallet considers max_outputs more of a soft limit. // So the wallet considers max_outputs more of a soft limit.
if eligible.len() > max_outputs { if eligible.len() > max_outputs {
for window in eligible.windows(max_outputs) { for window in eligible.windows(max_outputs) {
let eligible = window.iter().cloned().collect::<Vec<_>>(); let windowed_eligibles = window.iter().cloned().collect::<Vec<_>>();
if let Some(outputs) = self.select_from(amount, default_strategy, eligible) { if let Some(outputs) = self.select_from(amount, select_all, windowed_eligibles) {
return outputs; return outputs;
} }
} }
@ -564,9 +564,9 @@ impl WalletData {
if let Some(outputs) = self.select_from(amount, false, eligible.clone()) { if let Some(outputs) = self.select_from(amount, false, eligible.clone()) {
debug!(LOGGER, "Extending maximum number of outputs. {} outputs selected.", outputs.len()); debug!(LOGGER, "Extending maximum number of outputs. {} outputs selected.", outputs.len());
return outputs; return outputs;
} }
} else { } else {
if let Some(outputs) = self.select_from(amount, default_strategy, eligible.clone()) { if let Some(outputs) = self.select_from(amount, select_all, eligible.clone()) {
return outputs; return outputs;
} }
} }
@ -577,7 +577,7 @@ impl WalletData {
eligible.iter().take(max_outputs).cloned().collect() eligible.iter().take(max_outputs).cloned().collect()
} }
// Select the full list of outputs if we are using the default strategy. // Select the full list of outputs if we are using the select_all strategy.
// Otherwise select just enough outputs to cover the desired amount. // Otherwise select just enough outputs to cover the desired amount.
fn select_from( fn select_from(
&self, &self,
@ -640,7 +640,7 @@ pub struct PartialTx {
pub tx: String, pub tx: String,
} }
/// Builds a PartialTx /// Builds a PartialTx
/// aggsig_tx_context should contain the private key/nonce pair /// aggsig_tx_context should contain the private key/nonce pair
/// the resulting partial tx will contain the corresponding public keys /// the resulting partial tx will contain the corresponding public keys
pub fn build_partial_tx( pub fn build_partial_tx(
@ -658,7 +658,7 @@ pub fn build_partial_tx(
let mut pub_nonce = pub_nonce.serialize_vec(keychain.secp(), true); let mut pub_nonce = pub_nonce.serialize_vec(keychain.secp(), true);
let len = pub_nonce.clone().len(); let len = pub_nonce.clone().len();
let pub_nonce: Vec<_> = pub_nonce.drain(0..len).collect(); let pub_nonce: Vec<_> = pub_nonce.drain(0..len).collect();
PartialTx { PartialTx {
phase: PartialTxPhase::SenderInitiation, phase: PartialTxPhase::SenderInitiation,
amount: receive_amount, amount: receive_amount,