Author

Topic: How to set block.nBits in Genesis block (Read 2025 times)

newbie
Activity: 29
Merit: 0
May 22, 2018, 01:48:56 PM
#4
Yes this helps to fix the problem thanks
hero member
Activity: 525
Merit: 531
April 07, 2014, 11:08:25 AM
#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());
        }
hero member
Activity: 525
Merit: 531
April 03, 2014, 02:40:03 PM
#2
Here is my tutorial.
newbie
Activity: 19
Merit: 0
April 03, 2014, 11:05:28 AM
#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.
Jump to: