-
Notifications
You must be signed in to change notification settings - Fork 176
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
Staking and mining code cleanup, improvements #301
Staking and mining code cleanup, improvements #301
Conversation
Hey, cool. It looks like this one still tries to sign the same block over and over again, is that correct? |
@@ -19,7 +19,7 @@ using namespace std; | |||
// BitcoinMiner | |||
// | |||
|
|||
unsigned int nMinerSleep; | |||
volatile unsigned int nMinerSleep; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this for thread safety? IMO we should change all the current volatiles to std::atomic. At least that's what I think the intention was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is not changed after stake miner thread is started. Without the volatile modifier optimizer prevents me from changing it with debugger at run-time. It is just for debugger.
src/miner.cpp
Outdated
nLastBlockSubmitted = 0; | ||
return error("CheckStake: Nonce too low\r\n"); | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stray return.
src/miner.cpp
Outdated
MilliSleep(nMinerSleep); | ||
} | ||
SkipStake: | ||
MilliSleep(nMinerSleep); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove the minersleep flag altogether and just sleep 500ms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again. For use with debugger.
src/miner.cpp
Outdated
} | ||
|
||
|
||
//Verify we are still on the main chain | ||
|
||
if (IsLockTimeWithinMinutes(nLastBlockSolved,5)) | ||
if (false && IsLockTimeWithinMinutes(nLastBlockSolved,4)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not do this check anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
src/rpcmining.cpp
Outdated
@@ -51,6 +51,10 @@ Value getmininginfo(const Array& params, bool fHelp) | |||
obj.push_back(Pair("blocks", (int)nBestHeight)); | |||
obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize)); | |||
obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx)); | |||
try{ | |||
std::string superblock_num = mvApplicationCache["superblock;block_number"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be changed to ReadCache("superblock", "block_number");
. That implementation also injects a new object if one is missing, but I intend to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no intention to improve this api. Shoud I remove it then?
@@ -614,42 +614,30 @@ static bool CheckStakeKernelHashV3(CBlockIndex* pindexPrev, unsigned int nBits, | |||
double coin_age = std::abs((double)nTimeTx-(double)txPrev.nTime); | |||
double BitsAge = PORDiff * 144; //For every 100 Diff in Bits, two hours of coin age for researchers | |||
if (BitsAge > 86400) BitsAge=86400; //Limit to 24 hours (possibility of astronomical diff) | |||
// Halford : Explain to the Researcher why they are not staking: | |||
if (checking_local && LessVerbose(100)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this always evaluate to false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The code is refactored just few lines below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to stop reviewing that early. Read that code 3 times and realised twice that it was refactored :/
src/miner.cpp
Outdated
@@ -925,14 +918,16 @@ void StakeMiner(CWallet *pwallet) | |||
else | |||
{ | |||
msMiningErrors = "Stake block rejected"; | |||
if (fDebug) printf("Stake block rejected \r\n"); | |||
printf("Stake block rejected \r\n"); | |||
MilliSleep(1000); | |||
} | |||
SetThreadPriority(THREAD_PRIORITY_LOWEST); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove these thread priorities. A medium priority across the line should be fine since we're not doing any heavy work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
But i doubt it does anything since only root can ever raise priority of thread on linux.
src/rpcblockchain.cpp
Outdated
//12-20-2015 Support for Binary Superblocks | ||
std::string superblock=UnpackBinarySuperblock(bb.superblock); | ||
std::string neural_hash = GetQuorumHash(superblock); | ||
result.push_back(Pair("SuperblockHash", neural_hash)); | ||
result.push_back(Pair("SuperblockLength", (double)bb.superblock.length())); | ||
result.push_back(Pair("SuperblockLength", (long)superblock.length())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the meaning of "SuperblockLength". Will this cause any compatibility issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll change that
@denravonska performed the changes, please verify
Yes that unfortunately still true. Bigger refactoring required to close #295. |
84b6deb
to
ef0b0ef
Compare
src/init.cpp
Outdated
@@ -558,7 +558,7 @@ bool AppInit2() | |||
|
|||
fUseFastIndex = GetBoolArg("-fastindex", false); | |||
|
|||
nMinerSleep = GetArg("-minersleep", 500); | |||
nMinerSleep = GetArg("-minersleep", 8000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this will affect the shutdown time, right? Might be a non-issue though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, thinking about this again... There's a very specific second where staking is allowed, given the staking mask, right? With the previous 500ms sleep you were pretty much guaranteed to hit that window but with the new sleep there's a risk that you always sleep when the staking window is open. Or did I misinterpret the purpose of the mask?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a single second. There is specific period of 16 seconds where staking is allowed. The (bit inverse of) stake mask is applied to timestamp effectively eliminating the difference when of staking anywhere during that 16 seconds. It was introduced to save stakers from having to check every second.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaaaah, gotcha!
Excellent, I will try it out first thing tomorrow morning. |
Trying this on testnet now and I noticed that it started receiving blocks from the network while still loading the blocks from disk. I'm also seeing a lot of these in the log, but I guess that is to be expected with 0 mag and a semi-broken testnet:
|
src/kernel.cpp
Outdated
if (payment_age <= BitsAge) | ||
narr="Payment age < BitsAge: " + RoundToString(payment_age,3) + "; " + RoundToString(BitsAge,3); | ||
if (boincblock.Magnitude <= 1) | ||
narr="Magnitude too low for POR reward: " + RoundToString(payment_age,3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spam of this message in testnet. Remove warning? Print only when debug enabled? But it is important warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can keep it if the user is intended to get rewards. I think testnet doesn't have any projects whitelisted right now.
src/kernel.cpp
Outdated
if (coin_age <= RSA_WEIGHT) | ||
narr=" Coin Age < RSA_Weight: " + RoundToString(coin_age,0) + "; " + RoundToString(RSA_WEIGHT,0); | ||
if (coin_age <= 4*60*60) | ||
narr=" Coin Age Immature: " + RoundToString(coin_age,0) + "; 14400"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe i lost this condition
that's why my stakes are not accepted on testnet sometimes
I will close this request now. This one is only half done and I feel that more refactoring is needed. |
Are you sure? It's still an improvement over the current implementation. |
I misunderstood what a Close really means so I open this again with a push :) |
New status of this PR: @denravonska |
We should try to include this in the next staging merge if possible. Regarding the I can test it on testnet if you want to. |
Running this in testnet now. What's missing from the status? Getting |
Those indents thou in debug print for RSA_WEIGHT ;o) looks nice thou to have that added. |
Read the commit messages.
Experimental until declared ready!
Interest and Research subsidy visible in getmininginfo.
Check out
-debug=true -printtoconsole
;Block PoS hash and target visible in log;
Refactoring StakeMiner miner.cpp;