Skip to content

Commit

Permalink
[Staking] Fix Stake Split Threshold for PIV staking
Browse files Browse the repository at this point in the history
This reintroduces the calculation on wither or not the wallet should
"split" the PIV stake input.

Note: zPIV staking never splits, and it shouldn't.
  • Loading branch information
Fuzzbawls committed Apr 26, 2018
1 parent 5454f3c commit bd7cecb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/stakeinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ bool CZPivStake::CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut)
return true;
}

bool CZPivStake::CreateTxOuts(CWallet* pwallet, vector<CTxOut>& vout)
bool CZPivStake::CreateTxOuts(CWallet* pwallet, vector<CTxOut>& vout, CAmount nTotal)
{
LogPrintf("%s\n", __func__);

Expand Down Expand Up @@ -193,7 +193,7 @@ CAmount CPivStake::GetValue()
return txFrom.vout[nPosition].nValue;
}

bool CPivStake::CreateTxOuts(CWallet* pwallet, vector<CTxOut>& vout)
bool CPivStake::CreateTxOuts(CWallet* pwallet, vector<CTxOut>& vout, CAmount nTotal)
{
vector<valtype> vSolutions;
txnouttype whichType;
Expand All @@ -219,6 +219,11 @@ bool CPivStake::CreateTxOuts(CWallet* pwallet, vector<CTxOut>& vout)
scriptPubKey = scriptPubKeyKernel;

vout.emplace_back(CTxOut(0, scriptPubKey));

// Calculate if we need to split the output
if (nTotal / 2 > (CAmount)(pwallet->nStakeSplitThreshold * COIN))
vout.emplace_back(CTxOut(0, scriptPubKey));

return true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/stakeinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CStakeInput
virtual bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = 0) = 0;
virtual bool GetTxFrom(CTransaction& tx) = 0;
virtual CAmount GetValue() = 0;
virtual bool CreateTxOuts(CWallet* pwallet, vector<CTxOut>& vout) = 0;
virtual bool CreateTxOuts(CWallet* pwallet, vector<CTxOut>& vout, CAmount nTotal) = 0;
virtual bool GetModifier(uint64_t& nStakeModifier) = 0;
virtual bool IsZPIV() = 0;
virtual CDataStream GetUniqueness() = 0;
Expand Down Expand Up @@ -55,7 +55,7 @@ class CZPivStake : public CStakeInput
bool GetModifier(uint64_t& nStakeModifier) override;
CDataStream GetUniqueness() override;
bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = 0) override;
bool CreateTxOuts(CWallet* pwallet, vector<CTxOut>& vout) override;
bool CreateTxOuts(CWallet* pwallet, vector<CTxOut>& vout, CAmount nTotal) override;
bool MarkSpent(CWallet* pwallet, const uint256& txid);
bool IsZPIV() override { return true; }
int GetChecksumHeightFromMint();
Expand All @@ -82,7 +82,7 @@ class CPivStake : public CStakeInput
bool GetModifier(uint64_t& nStakeModifier) override;
CDataStream GetUniqueness() override;
bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = 0) override;
bool CreateTxOuts(CWallet* pwallet, vector<CTxOut>& vout) override;
bool CreateTxOuts(CWallet* pwallet, vector<CTxOut>& vout, CAmount nTotal) override;
bool IsZPIV() override { return false; }
};

Expand Down
14 changes: 8 additions & 6 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2936,18 +2936,20 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
// Found a kernel
LogPrintf("CreateCoinStake : kernel found\n");
nCredit += stakeInput->GetValue();
vector<CTxOut> vout;
if (!stakeInput->CreateTxOuts(this, vout)) {
LogPrintf("%s : failed to get scriptPubKey\n", __func__);
continue;
}
txNew.vout.insert(txNew.vout.end(), vout.begin(), vout.end());

// Calculate reward
CAmount nReward;
nReward = GetBlockValue(chainActive.Height() + 1);
nCredit += nReward;

// Create the output transaction(s)
vector<CTxOut> vout;
if (!stakeInput->CreateTxOuts(this, vout, nCredit)) {
LogPrintf("%s : failed to get scriptPubKey\n", __func__);
continue;
}
txNew.vout.insert(txNew.vout.end(), vout.begin(), vout.end());

CAmount nMinFee = 0;
if (!stakeInput->IsZPIV()) {
// Set output amount
Expand Down

0 comments on commit bd7cecb

Please sign in to comment.