Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wallet] Adjust staking properties to lower orphan rates. #617

Merged
merged 2 commits into from May 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/kernel.cpp
Expand Up @@ -314,7 +314,7 @@ bool Stake(CStakeInput* stakeInput, unsigned int nBits, unsigned int nTimeBlockF
bool fSuccess = false;
unsigned int nTryTime = 0;
int nHeightStart = chainActive.Height();
int nHashDrift = 45;
int nHashDrift = 30;
CDataStream ssUniqueID = stakeInput->GetUniqueness();
CAmount nValueIn = stakeInput->GetValue();
for (int i = 0; i < nHashDrift; i++) //iterate the hashing
Expand Down
25 changes: 12 additions & 13 deletions src/wallet.cpp
Expand Up @@ -2114,9 +2114,15 @@ bool CWallet::SelectStakeCoins(std::list<std::unique_ptr<CStakeInput> >& listInp

//zPIV
if (GetBoolArg("-zpivstake", true) && chainActive.Height() > Params().Zerocoin_Block_V2_Start() && !IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) {
//Add zPIV
set<CMintMeta> setMints = zpivTracker->ListMints(true, true, true);
//Only update zPIV set once per update interval
bool fUpdate = false;
static int64_t nTimeLastUpdate = 0;
if (GetAdjustedTime() - nTimeLastUpdate > nStakeSetUpdateTime) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going from GetTime() to GetAdjustedTime() might be a real good change for some users.

fUpdate = true;
nTimeLastUpdate = GetAdjustedTime();
}

set<CMintMeta> setMints = zpivTracker->ListMints(true, true, fUpdate);
for (auto meta : setMints) {
if (meta.hashStake == 0) {
CZerocoinMint mint;
Expand Down Expand Up @@ -2943,16 +2949,10 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
if (nBalance > 0 && nBalance <= nReserveBalance)
return false;

// Initialize as static and don't update the set on every run of CreateCoinStake() in order to lighten resource use
static int nLastStakeSetUpdate = 0;
static list<std::unique_ptr<CStakeInput> > listInputs;
if (GetTime() - nLastStakeSetUpdate > nStakeSetUpdateTime) {
listInputs.clear();
if (!SelectStakeCoins(listInputs, nBalance - nReserveBalance))
return false;

nLastStakeSetUpdate = GetTime();
}
// Get the list of stakable inputs
std::list<std::unique_ptr<CStakeInput> > listInputs;
if (!SelectStakeCoins(listInputs, nBalance - nReserveBalance))
return false;

if (listInputs.empty())
return false;
Expand Down Expand Up @@ -3083,7 +3083,6 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
}

// Successfully generated coinstake
nLastStakeSetUpdate = 0; //this will trigger stake set to repopulate next round
return true;
}

Expand Down