Bitcoin Forum
May 28, 2024, 11:41:55 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to set block.nBits in Genesis block  (Read 2004 times)
BC.NXT (OP)
Newbie
*
Offline Offline

Activity: 19
Merit: 0


View Profile
April 03, 2014, 04:05:28 PM
 #1

Hello,

Is any one encounter a problem below after change Litecoin's "block.nTime".

2014-04-03 15:53:46 Pre-allocating up to position 0x1000000 in blk00000.dat
2014-04-03 15:53:46 ERROR: CheckProofOfWork() : hash doesn't match nBits
2014-04-03 15:53:46 ERROR: CBlock::ReadFromDisk() : errors in block header
2014-04-03 15:53:46 *** Failed to read block

I check the error part in source code is this:

bool CheckProofOfWork(uint256 hash, unsigned int nBits)
{
    CBigNum bnTarget;
    bnTarget.SetCompact(nBits);

    // Check range
    if (bnTarget <= 0 || bnTarget > bnProofOfWorkLimit)
        return error("CheckProofOfWork() : nBits below minimum work");

    // Check proof of work matches claimed amount
    if (hash > bnTarget.getuint256())
        return error("CheckProofOfWork() : hash doesn't match nBits");

    return true;
}

any one can help me to solve this genesis block problem.
elbandi
Hero Member
*****
Offline Offline

Activity: 525
Merit: 529


View Profile
April 03, 2014, 07:40:03 PM
 #2

Here is my tutorial.
elbandi
Hero Member
*****
Offline Offline

Activity: 525
Merit: 529


View Profile
April 07, 2014, 04:08:25 PM
 #3

Here is the code:

Code:
        // If genesis block hash does not match, then generate new genesis hash.
        if (true && block.GetHash() != hashGenesisBlock)
        {
            printf("Searching for genesis block...\n");
            // This will figure out a valid hash and Nonce if you're
            // creating a different genesis block:
            uint256 hashTarget = CBigNum().SetCompact(block.nBits).getuint256();
            uint256 thash;
            char scratchpad[SCRYPT_SCRATCHPAD_SIZE];

            loop
            {
#if defined(USE_SSE2)
                // Detection would work, but in cases where we KNOW it always has SSE2,
                // it is faster to use directly than to use a function pointer or conditional.
#if defined(_M_X64) || defined(__x86_64__) || defined(_M_AMD64) || (defined(MAC_OSX) && defined(__i386__))
                // Always SSE2: x86_64 or Intel MacOS X
                scrypt_1024_1_1_256_sp_sse2(BEGIN(block.nVersion), BEGIN(thash), scratchpad);
#else
                // Detect SSE2: 32bit x86 Linux or Windows
                scrypt_1024_1_1_256_sp(BEGIN(block.nVersion), BEGIN(thash), scratchpad);
#endif
#else
                // Generic scrypt
                scrypt_1024_1_1_256_sp_generic(BEGIN(block.nVersion), BEGIN(thash), scratchpad);
#endif
                if (thash <= hashTarget)
                    break;
                if ((block.nNonce & 0xFFF) == 0)
                {
                    printf("nonce %08X: hash = %s (target = %s)\n", block.nNonce, thash.ToString().c_str(), hashTarget.ToString().c_str());
                }
                ++block.nNonce;
                if (block.nNonce == 0)
                {
                    printf("NONCE WRAPPED, incrementing time\n");
                    ++block.nTime;
                }
            }
            printf("block.nTime = %u \n", block.nTime);
            printf("block.nNonce = %u \n", block.nNonce);
            printf("block.GetHash = %s\n", block.GetHash().ToString().c_str());
        }
IluminumProject
Newbie
*
Offline Offline

Activity: 29
Merit: 0


View Profile
May 22, 2018, 06:48:56 PM
 #4

Yes this helps to fix the problem thanks
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!