Permalink
Browse files

Changes to StakeMiner

Add optional switch nMinerSleep and make sure we have a strong
connection before attempting stake.
  • Loading branch information...
Tranz5 committed Jul 13, 2014
1 parent b174a32 commit e781bb9f0afc46449161a46a206ca49359d6fec1
Showing with 26 additions and 11 deletions.
  1. +2 −0 src/init.cpp
  2. +18 −6 src/miner.cpp
  3. +6 −5 src/wallet.cpp
View
@@ -29,6 +29,7 @@ CWalletManager* pWalletManager;
// TODO: get rid of pwalletMain
CWallet* pwalletMain;
unsigned int nNodeLifespan;
unsigned int nMinerSleep;
enum Checkpoints::CPMode CheckpointsMode;
bool fUseFastIndex;
bool fConfChange;
@@ -448,6 +449,7 @@ bool AppInit2()
nNodeLifespan = GetArg("-addrlifespan", 7);
fUseFastIndex = GetBoolArg("-fastindex", true);
nMinerSleep = GetArg("-minersleep", 500);
CheckpointsMode = Checkpoints::STRICT;
std::string strCpMode = GetArg("-cppolicy", "strict");
View
@@ -18,9 +18,10 @@ using namespace std;
// BitcoinMiner
//
string strMintMessage = "Info: Minting suspended due to locked wallet.";
string strMintWarning;
extern unsigned int nMinerSleep;
int static FormatHashBlocks(void* pbuffer, unsigned int len)
{
unsigned char* pdata = (unsigned char*)pbuffer;
@@ -743,6 +744,8 @@ void StakeMiner(CWallet *pwallet)
// Make this thread recognisable as the mining thread
RenameThread("stake-miner");
bool fTryToSync = true;
// Each thread has its own counter
unsigned int nExtraNonce = 0;
@@ -753,20 +756,29 @@ void StakeMiner(CWallet *pwallet)
while (pwallet->IsLocked())
{
strMintWarning = strMintMessage;
MilliSleep(1000);
if (fShutdown)
return;
}
while (vNodes.empty() || IsInitialBlockDownload())
{
fTryToSync = true;
MilliSleep(1000);
if (fShutdown)
return;
}
strMintWarning = "";
if (fTryToSync)
{
fTryToSync = false;
if (vNodes.size() < 3 || nBestHeight < GetNumBlocksOfPeers())
{
printf("stake-miner sleeping while we get connectd.\n");
MilliSleep(60000);
continue;
}
}
//
// Create new block
@@ -784,10 +796,10 @@ void StakeMiner(CWallet *pwallet)
SetThreadPriority(THREAD_PRIORITY_NORMAL);
CheckStake(pblock.get(), *pwallet);
SetThreadPriority(THREAD_PRIORITY_LOWEST);
MilliSleep(500);
}
MilliSleep(500);
continue;
else
MilliSleep(nMinerSleep);
}
}
View
@@ -18,6 +18,7 @@
using namespace std;
extern int nStakeMaxAge;
extern int nMinerSleep;
//////////////////////////////////////////////////////////////////////////////
@@ -3026,13 +3027,13 @@ void CWalletManager::RestartStakeMiner()
if (!fShutdown)
{
fStopStaking = true;
MilliSleep(1000);
MilliSleep(nMinerSleep > 500 ? nMinerSleep * 2 : 1000);
}
//Re-Start Stake for the remaining wallets
// Re-Start Stake for the remaining wallets
if (!fShutdown)
{
fStopStaking = false;
MilliSleep(1000);
MilliSleep(500);
vector<string> vstrNames;
vector<boost::shared_ptr<CWallet> > vpWallets;
@@ -3082,7 +3083,7 @@ void CWalletManager::StakeForCharity()
}
}
//If no wallets are running s4c we want to turn off the global switch
// If no wallets are running s4c we want to turn off the global switch
if (!fStakeForCharityRunning)
fGlobalStakeForCharity=false;
}
@@ -3098,7 +3099,7 @@ bool CWalletManager::UnloadWallet(const std::string& strName)
{
printf ("Halting Stake Mining while we unload wallet(s)\n");
fStopStaking = true;
MilliSleep(1000);
MilliSleep(nMinerSleep > 500 ? nMinerSleep * 2 : 1000);
}
boost::shared_ptr<CWallet> spWallet(wallets[strName]);
printf("Unloading wallet %s\n", strName.c_str());

0 comments on commit e781bb9

Please sign in to comment.