settle the fuck down.
this is a fix for KGW.
the nBits function (provided by an include to 'boost/algorithm') doesn't deal with negatives.
target difficulty as we all know, is not meant to drop below zero (it will get very close however).
KGW lets this happen (as an adjustment mechanism), the problem being that the coin daemon's ContextualCheckBlockHeader function will spit it, when it produces an incorrect nBits figure when it tries to validate the block.
Feel free to pop this into the function (in lieu of standard code/or the absolute patch); run it and see what happens:
if ((!Params().SkipProofOfWorkCheck()) &&
(block.nBits != GetNextWorkRequired(pindexPrev, &block))){
LogPrintf("ContextualCheckBlockHeader,nHeight=%d,block.nBits=%d,GetNextWorkRequired=%d\n",nHeight,block.nBits,GetNextWorkRequired(pindexPrev, &block));
return state.DoS(100, error("%s : incorrect proof of work", __func__),
REJECT_INVALID, "bad-diffbits"); */
}
when the nBits conversion is called again, the value it returns will be incredibly close (shown as an integer, it will be off by 4 or 5) because it has wrapped past zero, which an unsigned variable is not meant to do (a signed variable can, even binary which is why there is a 'sign' bit denoting whether the value is positive or negative). the above snippet will show you that the figure differs from what is expected.
i ran into a similar issue whilst working with an upgraded altcoin codebase recently, and have been tearing my f**ken hair out as to why the existing mainnet chain doesn't match the difficulty algorithms. i actually owe a thanks to whoever came up with the commit (https://github.com/dashpay/dash/commit/efca207c134516c5ddf7ce7b681ed983909a826f) as i came pretty close to adding individual block exceptions for the contextual checker (ew).
I will let that sink in for awhile, for the more slower trolls on this thread
* point 2 : the code that is referred to in this thread is for Testnet
not to be a pain; i can't find that commit.
the code isn't for testnet; testnet is mentioned as a condition in the if clause, the code is for the 'if else' condition.
this is whats currently in the official repository at the moment:
which actually integrates the difficulty portion of https://github.com/vertoe/darkcoin_subsidy/blob/master/darkcoin_subsidy.cpp in a much neater manner.
all smoke no fire i'm afraid.
again, cheers to whoever wrote that KGW absolute value fix hero
james