Skip to content

Commit

Permalink
hashsettings RPC
Browse files Browse the repository at this point in the history
hashsettings <drift/interval><seconds>
ex: 'hashsettings drift' will return the current drift settings
ex: 'hashsettings interval' will return the current interval settings
ex: hashsettings drift 45
ex: hashsettings interval 20
ex: 'hashsettings default' returns the settings to default

hashdrift is how many second into the future your wallet will stake in
one hashing burst. Interval is how often your client will search for new
hashes. If you set your hashdrift to 45, then your client will create 45
unique proof of stake hashes, the only thing changing the hash result is
the timestamp included, thus you hash 45 seconds into the future.\n"
"Each hash is an attempt to meet the staking target. If you don't hit
the staking target, your client will pause staking for the set interval.
If the interval is 22 seconds, the wallet will create 45 hashes, wait 22
seconds, then create 45 hashes. Approximately 23 of those hashes will be
identical as the previous rounds hashes.
  • Loading branch information
presstab committed Jun 26, 2015
1 parent e6de120 commit 3b253ac
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ static const CRPCCommand vRPCCommands[] =
{ "setgenerate", &setgenerate, true, false },
{ "gethashespersec", &gethashespersec, true, false },
{ "listblocks", &listblocks, false, false },
{ "hashdrift", &hashdrift, false, false },
{ "hashsettings", &hashsettings, false, false },
};

CRPCTable::CRPCTable()
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ extern json_spirit::Value getpotentialstake(const json_spirit::Array& params, bo
extern json_spirit::Value getconfs(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value strictprotocol(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value strictincoming(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value hashdrift(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value hashsettings(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4505,7 +4505,7 @@ void BitcoinMiner(CWallet *pwallet, bool fProofOfStake)

if(mapHashedBlocks.count(nBestHeight)) //search our map of hashed blocks, see if bestblock has been hashed yet
{
if(GetTime() - mapHashedBlocks[nBestHeight] < min((int)(pwallet->nHashDrift * 0.5), 180)) // wait half of the nHashDrift with max wait of 3 minutes
if(GetTime() - mapHashedBlocks[nBestHeight] < max(pwallet->nHashInterval, (unsigned int)1)) // wait half of the nHashDrift with max wait of 3 minutes
{
Sleep(2500); // 2.5 second sleep
continue;
Expand Down
72 changes: 55 additions & 17 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2645,26 +2645,64 @@ Value strictincoming(const Array& params, bool fHelp)
}

// presstab HyperStake
Value hashdrift(const Array& params, bool fHelp)
Value hashsettings(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
if (fHelp || params.size() > 2 || params.size() == 0)
throw runtime_error(
"hashdrift <seconds to hash into the future>\n"
"WARNING: too high of a hash drift will cause orphans");
if(params.size() < 1)
return boost::lexical_cast<string>(pwalletMain->nHashDrift);
"hashsettings <drift/interval><seconds>\n"
"ex: 'hashsettings drift' will return the current drift settings\n"
"ex: 'hashsettings interval' will return the current interval settings\n"
"ex: hashsettings drift 45\n"
"ex: hashsettings interval 20\n"
"ex: 'hashsettings default' returns the settings to default\n"
"hashdrift is how many second into the future your wallet will stake in one hashing burst\n"
"interval is how often your client will search for new hashes\n"
"if you set your hashdrift to 45, then your client will create 45 unique proof of stake hashes, the only thing changing the hash result is the timestamp included, thus you hash 45 seconds into the future.\n"
"Each hash is an attempt to meet the staking target. If you don't hit the staking target, your client will pause staking for the set interval. \n"
"If the interval is 22 seconds, the wallet will create 45 hashes, wait 22 seconds, then create 45 hashes. Approximately 23 of those hashes will be identical as the previous rounds hashes.\n"
"WARNING: timedrift allowance is 60 seconds too high of a hash drift will cause orphans");
if(params.size() < 2)
{
if(params[0].get_str() == "drift")
return boost::lexical_cast<string>(pwalletMain->nHashDrift);
else if(params[0].get_str() == "interval")
return boost::lexical_cast<string>(pwalletMain->nHashInterval);
else if(params[0].get_str() == "default")
{
CWalletDB walletdb(pwalletMain->strWalletFile);
pwalletMain->nHashDrift = 45;
pwalletMain->nHashInterval = 22;
walletdb.WriteHashDrift(45);
walletdb.WriteHashInterval(22);
return "Hash Settings returned to default";
}
}

CWalletDB walletdb(pwalletMain->strWalletFile);
unsigned int nHashDrift = boost::lexical_cast<unsigned int>(params[0].get_str());
if(nHashDrift > 60)
return "You can not set your hashdrift to be greater than 60 seconds";

bool fSuccess = walletdb.WriteHashDrift(nHashDrift);
pwalletMain->nHashDrift = nHashDrift;

if(fSuccess)
return "Hashdrift set and save to DB";
else
return "Hashdrift set but failed to write to DB";
if(params[0].get_str() == "drift")
{
unsigned int nHashDrift = boost::lexical_cast<unsigned int>(params[1].get_str());
if(nHashDrift > 60)
return "You can not set your hashdrift to be greater than 60 seconds";
else if(nHashDrift < 1)
return "Hash drift too low";

pwalletMain->nHashDrift = nHashDrift;
if(walletdb.WriteHashDrift(nHashDrift))
return "Hashdrift set and save to DB";
else
return "Hashdrift set but failed to write to DB";
}
else if(params[0].get_str() == "interval")
{
unsigned int nHashInterval = boost::lexical_cast<unsigned int>(params[1].get_str());
if(nHashInterval < 1)
return "Interval too low";
pwalletMain->nHashInterval = nHashInterval;
if(walletdb.WriteHashInterval(nHashInterval))
return "HashInterval set and save to DB";
else
return "HashInterval set but failed to write to DB";
}
}

3 changes: 3 additions & 0 deletions src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class CWallet : public CCryptoKeyStore

// Stake Settings
unsigned int nHashDrift;
unsigned int nHashInterval;
uint64 nStakeSplitThreshold;

// DisableStake
Expand Down Expand Up @@ -133,6 +134,7 @@ class CWallet : public CCryptoKeyStore
// Stake Settings
nHashDrift = 45;
nStakeSplitThreshold = 2000;
nHashInterval = 22;

//MultiSend
vMultiSend.clear();
Expand Down Expand Up @@ -164,6 +166,7 @@ class CWallet : public CCryptoKeyStore
// Stake Settings
nHashDrift = 45;
nStakeSplitThreshold = 2000;
nHashInterval = 22;

//MultiSend
vMultiSend.clear();
Expand Down
6 changes: 6 additions & 0 deletions src/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
ssValue >> nHashDrift;
pwallet->nHashDrift = nHashDrift;
}
else if(strType == "hashinterval")//presstab HyperStake
{
unsigned int nHashInterval;
ssValue >> nHashInterval;
pwallet->nHashInterval = nHashInterval;
}
} catch (...)
{
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/walletdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ class CWalletDB : public CDB
nWalletDBUpdated++;
return Write(std::string("hashdrift"), nHashDrift, true);
}
//presstab HyperStake
bool WriteHashInterval(unsigned int nHashInterval)
{
nWalletDBUpdated++;
return Write(std::string("hashinterval"), nHashInterval, true);
}
bool WriteDefaultKey(const CPubKey& vchPubKey)
{
nWalletDBUpdated++;
Expand Down

0 comments on commit 3b253ac

Please sign in to comment.