Bug fix in work decay calculation

This commit is contained in:
myriadcoin
2015-01-10 09:51:48 +02:00
parent b6d1bb8e57
commit 7fb2147de1
+31 -3
View File
@@ -690,6 +690,7 @@ enum BlockStatus {
const int64_t nBlockAlgoWorkWeightStart = 142000; // block where algo work weighting starts
const int64_t nBlockAlgoNormalisedWorkStart = 740000; // block where algo combined weight starts
const int64_t nBlockAlgoNormalisedWorkDecayStart = 866000; // block where weight decay starts
const int64_t nBlockAlgoNormalisedWorkDecayStart2 = 932000; // block where weight decay starts
const int64_t nBlockSequentialAlgoRuleStart = 740000; // block where sequential algo rule starts
const int64_t nBlockSequentialAlgoRuleStart2 = 766000; // block where sequential algo rule starts
const int nBlockSequentialAlgoMaxCount = 6; // maximum sequential blocks of same algo
@@ -878,6 +879,30 @@ public:
return Params().ProofOfWorkLimit(algo);
}
CBigNum GetPrevWorkForAlgoWithDecay2(int algo) const
{
int nDistance = 0;
CBigNum nWork;
CBlockIndex* pindex = this->pprev;
while (pindex)
{
if (nDistance > 32)
{
return CBigNum(0);
}
if (pindex->GetAlgo() == algo)
{
CBigNum nWork = pindex->GetBlockWork();
nWork *= (32 - nDistance);
nWork /= 32;
return nWork;
}
pindex = pindex->pprev;
nDistance++;
}
return CBigNum(0);
}
CBigNum GetBlockWork() const
{
CBigNum bnTarget;
@@ -929,10 +954,13 @@ public:
{
if (algo != nAlgo)
{
if (nHeight >= nBlockAlgoNormalisedWorkDecayStart)
nBlockWork += GetPrevWorkForAlgoWithDecay(algo);
if (nHeight >= nBlockAlgoNormalisedWorkDecayStart2)
nBlockWork += GetPrevWorkForAlgoWithDecay2(algo);
else
nBlockWork += GetPrevWorkForAlgo(algo);
if (nHeight >= nBlockAlgoNormalisedWorkDecayStart)
nBlockWork += GetPrevWorkForAlgoWithDecay(algo);
else
nBlockWork += GetPrevWorkForAlgo(algo);
}
}
bnRes = nBlockWork / NUM_ALGOS;