mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
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:
parent
8b2f9503c9
commit
d28f37d5b3
2 changed files with 13 additions and 13 deletions
|
@ -35,7 +35,7 @@ pub fn issue_send_tx(
|
|||
minimum_confirmations: u64,
|
||||
dest: String,
|
||||
max_outputs: usize,
|
||||
selection_strategy: bool,
|
||||
selection_strategy_is_use_all: bool,
|
||||
) -> Result<(), Error> {
|
||||
checker::refresh_outputs(config, keychain)?;
|
||||
|
||||
|
@ -53,7 +53,7 @@ pub fn issue_send_tx(
|
|||
minimum_confirmations,
|
||||
lock_height,
|
||||
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
|
||||
|
@ -162,7 +162,7 @@ fn build_send_tx(
|
|||
minimum_confirmations: u64,
|
||||
lock_height: u64,
|
||||
max_outputs: usize,
|
||||
default_strategy: bool,
|
||||
selection_strategy_is_use_all: bool,
|
||||
) -> Result<(Transaction, BlindingFactor, Vec<OutputData>, Identifier), Error> {
|
||||
let key_id = keychain.clone().root_key_id();
|
||||
|
||||
|
@ -174,7 +174,7 @@ fn build_send_tx(
|
|||
current_height,
|
||||
minimum_confirmations,
|
||||
max_outputs,
|
||||
default_strategy,
|
||||
selection_strategy_is_use_all,
|
||||
)
|
||||
})?;
|
||||
|
||||
|
|
|
@ -529,7 +529,7 @@ impl WalletData {
|
|||
current_height: u64,
|
||||
minimum_confirmations: u64,
|
||||
max_outputs: usize,
|
||||
default_strategy: bool,
|
||||
select_all: bool,
|
||||
) -> Vec<OutputData> {
|
||||
// first find all eligible outputs based on number of confirmations
|
||||
let mut eligible = self.outputs
|
||||
|
@ -546,7 +546,7 @@ impl WalletData {
|
|||
|
||||
// use a sliding window to identify potential sets of possible outputs to spend
|
||||
// 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.
|
||||
// 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,
|
||||
|
@ -554,8 +554,8 @@ impl WalletData {
|
|||
// So the wallet considers max_outputs more of a soft limit.
|
||||
if eligible.len() > max_outputs {
|
||||
for window in eligible.windows(max_outputs) {
|
||||
let eligible = window.iter().cloned().collect::<Vec<_>>();
|
||||
if let Some(outputs) = self.select_from(amount, default_strategy, eligible) {
|
||||
let windowed_eligibles = window.iter().cloned().collect::<Vec<_>>();
|
||||
if let Some(outputs) = self.select_from(amount, select_all, windowed_eligibles) {
|
||||
return outputs;
|
||||
}
|
||||
}
|
||||
|
@ -564,9 +564,9 @@ impl WalletData {
|
|||
if let Some(outputs) = self.select_from(amount, false, eligible.clone()) {
|
||||
debug!(LOGGER, "Extending maximum number of outputs. {} outputs selected.", outputs.len());
|
||||
return outputs;
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
@ -577,7 +577,7 @@ impl WalletData {
|
|||
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.
|
||||
fn select_from(
|
||||
&self,
|
||||
|
@ -640,7 +640,7 @@ pub struct PartialTx {
|
|||
pub tx: String,
|
||||
}
|
||||
|
||||
/// Builds a PartialTx
|
||||
/// Builds a PartialTx
|
||||
/// aggsig_tx_context should contain the private key/nonce pair
|
||||
/// the resulting partial tx will contain the corresponding public keys
|
||||
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 len = pub_nonce.clone().len();
|
||||
let pub_nonce: Vec<_> = pub_nonce.drain(0..len).collect();
|
||||
|
||||
|
||||
PartialTx {
|
||||
phase: PartialTxPhase::SenderInitiation,
|
||||
amount: receive_amount,
|
||||
|
|
Loading…
Reference in a new issue