Skip to content

Commit 05ee734

Browse files
committed
privatesend: Fix countPossibleOutputs
- Fix off by one issue - Respect max outputs threshold
1 parent 2f6cb63 commit 05ee734

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/privatesend/privatesend-client.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,10 +1650,17 @@ bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate,
16501650

16511651
auto countPossibleOutputs = [&](CAmount nAmount) -> int {
16521652
std::vector<CAmount> vecOutputs;
1653-
while (txBuilder.TryAddOutputs(vecOutputs)) {
1653+
while(true) {
1654+
// Create an potential output
16541655
vecOutputs.push_back(nAmount);
1656+
if (!txBuilder.TryAddOutputs(vecOutputs) || txBuilder.CountOutputs() + vecOutputs.size() >= PRIVATESEND_DENOM_OUTPUTS_THRESHOLD) {
1657+
// If its not possible to add it due to insufficient amount left or total number of outputs exceeds
1658+
// PRIVATESEND_DENOM_OUTPUTS_THRESHOLD drop the output again and stop trying.
1659+
vecOutputs.pop_back();
1660+
break;
1661+
}
16551662
}
1656-
return vecOutputs.size();
1663+
return static_cast<int>(vecOutputs.size());
16571664
};
16581665

16591666
// Go big to small

0 commit comments

Comments
 (0)