Skip to content

Commit

Permalink
Fund calculation inconsistent (#582) Milestone/testnet1 (#596)
Browse files Browse the repository at this point in the history
* Add 'sent' to wallet info output (#288)
* Fund calculation inconsistent (#582)
  • Loading branch information
heunglee authored and ignopeverell committed Jan 11, 2018
1 parent c1f8600 commit 864fab3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion wallet/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,28 @@ impl WalletData {
// sort eligible outputs by increasing value
eligible.sort_by_key(|out| out.value);

// 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):
// 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,
// the wallet should allow going over it to satisfy what the user wants to send.
// 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) {
return outputs;
}
}
// Not exist in any window of which total amount >= amount.
// Then take coins from the smallest one up to the total amount of selected coins = the amount.
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()) {
return outputs;
Expand Down

0 comments on commit 864fab3

Please sign in to comment.