From c6e929c756ddb121c73efc8daa5699f7d0ee60d2 Mon Sep 17 00:00:00 2001 From: myriadcoin Date: Sun, 7 Dec 2014 11:00:08 +0200 Subject: [PATCH] Proposed change to add decay to block work --- src/main.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main.h b/src/main.h index 5d04d1a0..524bfb17 100644 --- a/src/main.h +++ b/src/main.h @@ -689,6 +689,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 nBlockAlgoNormalisedWorkStart2 = 99990000; // block where algo combined weight starts with decay 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 @@ -833,7 +834,6 @@ public: CBigNum GetPrevWorkForAlgo(int algo) const { - CBigNum nWork; CBlockIndex* pindex = this->pprev; while (pindex) { @@ -846,6 +846,30 @@ public: return Params().ProofOfWorkLimit(algo); } + CBigNum GetPrevWorkForAlgoWithDecay(int algo) const + { + int nDistance = 0; + CBigNum nWork; + CBlockIndex* pindex = this->pprev; + while (pindex) + { + if (nDistance > 32) + { + return Params().ProofOfWorkLimit(algo); + } + if (pindex->GetAlgo() == algo) + { + CBigNum nWork = pindex->GetBlockWork(); + nWork = nWork * (32 - nDistance); + nWork = nWork / 32; + return nWork; + } + pindex = pindex->pprev; + nDistance++; + } + return Params().ProofOfWorkLimit(algo); + } + CBigNum GetBlockWork() const { CBigNum bnTarget; @@ -897,7 +921,10 @@ public: { if (algo != nAlgo) { - nBlockWork += GetPrevWorkForAlgo(algo); + if (nHeight >= nBlockAlgoNormalisedWorkStart2) + nBlockWork += GetPrevWorkForAlgoWithDecay(algo); + else + nBlockWork += GetPrevWorkForAlgo(algo); } } bnRes = nBlockWork / NUM_ALGOS;