Author

Topic: Retargeting algorithm (Read 1960 times)

hero member
Activity: 589
Merit: 500
September 04, 2011, 08:51:40 PM
#7
I post one example of such algorithms as the following code segment. Just an example, it's not usable directly, some necessary validity changes and modifications, optimization should be added for the actual application.

Anyone can use it as long as you find it useful.

------------------------------------------------------------------

// Go back by what we want to be 14 days worth of blocks
    const CBlockIndex* pindexFirst = pindexLast;
    for (int i = 0; pindexFirst && i < nInterval-1; i++)
        pindexFirst = pindexFirst->pprev;
    assert(pindexFirst);

    // Limit adjustment step
    int64 nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime();
    printf("  nActualTimespan = %"PRI64d"  before bounds\n", nActualTimespan);

    int64 nThisTimespan = nActualTimespan;

   if (nActualTimespan < nTargetTimespan/4)
        nActualTimespan = nTargetTimespan/4;
    if (nActualTimespan > nTargetTimespan*4)
        nActualTimespan = nTargetTimespan*4;

    
    const CBlockIndex* pindexPreviousFirst = pindexFirst;
    for (int i = 0; pindexPreviousFirst && i < nInterval-1; i++)
        pindexPreviousFirst = pindexPreviousFirst->pprev;
    assert(pindexPreviousFirst);                                                        

    int64 nPreviousTimespan = pindexFirst->GetBlockTime() - pindexPreviousFirst->GetBlockTime();


// Retarget
    CBigNum bnNew;
    bnNew.SetCompact(pindexLast->nBits);
    bnNew *= nActualTimespan;

    if ( ( nPreviousTimespan > nThisTimespan ) && ( nPreviousTimespan < nTargetTimespan ) )
    {
                
         bnNew *= 2;
         bnNew /= ( nTargetTimespan + nActualTimespan );
    
     }
     else if ( ( nPreviousTimespan < nThisTimespan ) && ( nPreviousTimespan > nTargetTimespan ) )
     {
          bnNew *=  nActualTimespan;
          bnNew /= ( nTargetTimespan * nTargetTimespan );
      }
      else
      {
          
               bnNew /= nTargetTimespan;
       }

      
      if (bnNew > bnProofOfWorkLimit)
        bnNew = bnProofOfWorkLimit;

    /// debug print
    printf("GetNextWorkRequired RETARGET\n");
    printf("nTargetTimespan = %"PRI64d"    nActualTimespan = %"PRI64d"\n", nTargetTimespan, nActualTimespan);
    printf("Before: %08x  %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString().c_str());
    printf("After:  %08x  %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString().c_str());

    return bnNew.GetCompact();

hero member
Activity: 589
Merit: 500
August 28, 2011, 07:40:44 PM
#6
A similar coin can be defined:
1) every 15/4 minutes generate a block
2) each block rewards 32 coins
3) retarget every 64 blocks or 128 blocks
4) the rewards for each block changed to a half every 262144 blocks
5) the limited amount is 16777216 coins
6) zeta in the retargeting algorithm can be simply defined or calculate it in site with theoretical expected probability and an attractive parameter

P.S. could someone get a code to do some analysis on SC?
a) actual consuming time for each block
b) average time of a block in a window of 240 blocks at the same difficulty
c) actual distribution for the block generation time
d) some curves for the quantities change with time

I am not familiar with coding, if someone is interesting, take it and do it, and if you get something please post here. Thanks!

hero member
Activity: 589
Merit: 500
August 28, 2011, 12:57:49 AM
#5
Retargeting algorithm before seems that difficulty was constantly changing. Why should be that? Why not adjust it in time, that means, for example, adjust it with an adjustment factor t_0/t and also an adjustment coefficient zeta is multiplied, zeta = 0.8 for some case and zeta = 1.1 for the other case as an example. Furthermore, zeta can also be adjusted automatically according to some rules.

One more problem is how to get more and more miners and mining power to involve?


It may be not a problem.
legendary
Activity: 2492
Merit: 1473
LEALANA Bitcoin Grim Reaper
August 28, 2011, 12:42:56 AM
#4
1) Spend Money (for mining rigs, electricity)
2) Mine BTC
3) Huh
4) Profit!

Sorry, my question is how to transfer the existing power to the new fork by an algorithm so as to let the fork reach a modest scale.


He answered u correctly. You pay the miners for their rigs and the electricity bills and they mine on the network of your choosing...etc..
hero member
Activity: 589
Merit: 500
August 27, 2011, 10:31:03 PM
#3
1) Spend Money (for mining rigs, electricity)
2) Mine BTC
3) Huh
4) Profit!

Sorry, my question is how to transfer the existing power to the new fork by an algorithm so as to let the fork reach a modest scale.
hero member
Activity: 560
Merit: 500
August 27, 2011, 10:07:02 PM
#2
1) Spend Money (for mining rigs, electricity)
2) Mine BTC
3) Huh
4) Profit!
hero member
Activity: 589
Merit: 500
August 27, 2011, 09:58:38 PM
#1
Retargeting algorithm before seems that difficulty was constantly changing. Why should be that? Why not adjust it in time, that means, for example, adjust it with an adjustment factor t_0/t and also an adjustment coefficient zeta is multiplied, zeta = 0.8 for some case and zeta = 1.1 for the other case as an example. Furthermore, zeta can also be adjusted automatically according to some rules.

One more problem is how to get more and more miners and mining power to involve?
Jump to: