Skip to content

Commit

Permalink
release 0.14.3
Browse files Browse the repository at this point in the history
don't create outputs that are less than target amount
  • Loading branch information
backpacker69 committed May 13, 2024
2 parents 88e6408 + 23e0a54 commit 6e178c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2024)
define(_PEERCOIN_VERSION_MAJOR, 0)
define(_PEERCOIN_VERSION_MINOR, 14)
define(_PEERCOIN_VERSION_REVISION, 2)
define(_PEERCOIN_VERSION_REVISION, 3)
define(_PEERCOIN_VERSION_BUILD, 0)
define(_PEERCOIN_VERSION_RC, 0)
define(_COPYRIGHT_HOLDERS,[The %s developers])
Expand Down
20 changes: 14 additions & 6 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3794,13 +3794,19 @@ bool CWallet::CreateCoinStake(ChainstateManager& chainman, const CWallet* pwalle
if (nTargetOutputAmount < MIN_TARGET_OUTPUT_AMOUNT)
nTargetOutputAmount = MIN_TARGET_OUTPUT_AMOUNT;

// If the available balance split by target amount would exceed max minting
// utxos, reset the target amount and nCombineThreshold to evenly split
// available balance
bool constrainToMaxUtxos = (nAllowedBalance / nTargetOutputAmount) > maxMintingUtxos;
CAmount nCombineThreshold;
// if available balance split by target amount would exceed max minting utxos
// reset target amount and nCombineThreshold to evenly split available balance
if ((nAllowedBalance / nTargetOutputAmount) > maxMintingUtxos) {
if (constrainToMaxUtxos) {
nTargetOutputAmount = nAllowedBalance / maxMintingUtxos;
// Combine all utxos under the target amount when attempting to optimise
// for max minting utxos
nCombineThreshold = nTargetOutputAmount;
} else
// Otherwise do not combine utxos near the target to avoid consuming
// coinage and to prevent combining recently split utxos
nCombineThreshold = nTargetOutputAmount / RECOMBINE_DIVISOR;

for (const auto& pcoin : result->GetInputSet())
Expand Down Expand Up @@ -3866,17 +3872,19 @@ bool CWallet::CreateCoinStake(ChainstateManager& chainman, const CWallet* pwalle
{
// Clear outputs
txNew.vout.erase(txNew.vout.begin() + 1u+bMinterKey, txNew.vout.end());

// Assume success
bool outputsOk = true;

// split and set amounts based on rfc28
if (pwallet->m_split_coins) {
CAmount current = nCredit - nMinFee;
double ratio = current / nTargetOutputAmount;
// Obtain the optimal number of outputs and clamp it to maxOutputs to ensure the fee is not exceeded
int desiredOutputs = std::min(
int(std::floor((std::sqrt(4 * std::pow(ratio, 2) + 1) + 1) / 2)),
constrainToMaxUtxos
// When constraining to the max utxos, ensure the output amount is no less than the target
? std::max(int(ratio), 1)
// Otherwise minimise the log-distance from the target
: int(std::floor((std::sqrt(4 * std::pow(ratio, 2) + 1) + 1) / 2)),
maxOutputs
);

Expand Down

0 comments on commit 6e178c9

Please sign in to comment.