Post
Topic
Board Announcements (Altcoins)
Re: [ANN] Catcoin - NEW THREAD - FORK INCOMING AT BLOCK 21346 - Scrypt MEOW!
by
kuroman
on 03/02/2014, 07:36:11 UTC
You really give yourself a hard time.

Don't you think it's finnaly time to check Kmotos Gravity Well code?

Just open the main.cpp of any Coin that have it (KDC, Vent, Mega) and study it. Just reading it will give you some good ideas I am sure. Also about how to do the averaging better/more correctly.


We are a community coin. We don't add features that most people can't relate to. If we add black magic, fewer people will contribute to the vitality of the coin. Then we die.

We are going to restructure the coin so that this stuff is easier to deal with.

Correct me if I'm wrong, but from your comment I get the feeling that you didn't make the effort to look it up and understand how it work, and I think it's fair to make a judgement about it after you do those things. and btw it is a simpler solution than SMA36LIM12

For those who didn't bother looking at it or who aren't tech savies let me explain to you how kimoto gravity works (from my understanding) :
1-Diff retarget is made every single block
2-The function for diff retarget depends on hashrate or rather the time to solve a block
It uses this function KGW = 1 + (0.7084 * pow((double(PastBlocksMass)/double(144)), -1.228))
So if fast rate is high the function above is applied if/when it's the opposite 1/KGW is applied
Here is the whole code behind it, there is nothing magical about it just a simple math formula applied dynamicly :

Code:
unsigned int static KimotoGravityWell(const CBlockIndex* pindexLast, const CBlockHeader *pblock, uint64 TargetBlocksSpacingSeconds, uint64 PastBlocksMin, uint64 PastBlocksMax) {
        /* current difficulty formula, megacoin - kimoto gravity well */
        const CBlockIndex  *BlockLastSolved                                = pindexLast;
        const CBlockIndex  *BlockReading                                = pindexLast;
        const CBlockHeader *BlockCreating                                = pblock;
                                                BlockCreating                                = BlockCreating;
        uint64                                PastBlocksMass                                = 0;
        int64                                PastRateActualSeconds                = 0;
        int64                                PastRateTargetSeconds                = 0;
        double                                PastRateAdjustmentRatio                = double(1);
        CBigNum                                PastDifficultyAverage;
        CBigNum                                PastDifficultyAveragePrev;
        double                                EventHorizonDeviation;
        double                                EventHorizonDeviationFast;
        double                                EventHorizonDeviationSlow;
        
    if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || (uint64)BlockLastSolved->nHeight < PastBlocksMin) { return bnProofOfWorkLimit.GetCompact(); }
        
        for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) {
                if (PastBlocksMax > 0 && i > PastBlocksMax) { break; }
                PastBlocksMass++;
                
                if (i == 1)        { PastDifficultyAverage.SetCompact(BlockReading->nBits); }
                else                { PastDifficultyAverage = ((CBigNum().SetCompact(BlockReading->nBits) - PastDifficultyAveragePrev) / i) + PastDifficultyAveragePrev; }
                PastDifficultyAveragePrev = PastDifficultyAverage;
                
                PastRateActualSeconds                        = BlockLastSolved->GetBlockTime() - BlockReading->GetBlockTime();
                PastRateTargetSeconds                        = TargetBlocksSpacingSeconds * PastBlocksMass;
                PastRateAdjustmentRatio                        = double(1);
                if (PastRateActualSeconds < 0) { PastRateActualSeconds = 0; }
                if (PastRateActualSeconds != 0 && PastRateTargetSeconds != 0) {
                PastRateAdjustmentRatio                        = double(PastRateTargetSeconds) / double(PastRateActualSeconds);
                }
                EventHorizonDeviation                        = 1 + (0.7084 * pow((double(PastBlocksMass)/double(144)), -1.228));
                EventHorizonDeviationFast                = EventHorizonDeviation;
                EventHorizonDeviationSlow                = 1 / EventHorizonDeviation;
                
                if (PastBlocksMass >= PastBlocksMin) {
                        if ((PastRateAdjustmentRatio <= EventHorizonDeviationSlow) || (PastRateAdjustmentRatio >= EventHorizonDeviationFast)) { assert(BlockReading); break; }
                }
                if (BlockReading->pprev == NULL) { assert(BlockReading); break; }
                BlockReading = BlockReading->pprev;
        }
        
        CBigNum bnNew(PastDifficultyAverage);
        if (PastRateActualSeconds != 0 && PastRateTargetSeconds != 0) {
                bnNew *= PastRateActualSeconds;
                bnNew /= PastRateTargetSeconds;
        }
    if (bnNew > bnProofOfWorkLimit) { bnNew = bnProofOfWorkLimit; }
        
    /// debug print
    printf("Difficulty Retarget - Kimoto Gravity Well\n");
    printf("PastRateAdjustmentRatio = %g\n", PastRateAdjustmentRatio);
    printf("Before: %08x  %s\n", BlockLastSolved->nBits, CBigNum().SetCompact(BlockLastSolved->nBits).getuint256().ToString().c_str());
    printf("After:  %08x  %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString().c_str());
        
        return bnNew.GetCompact();
}


The above is the code for the Gravity Well, just for reference's sake.