7

I create my new altercoin,but when I first run it,it already shows:"No block source available 5 week(s) behind". And I start anther computer in the LAN, they link succefully. I use the code of Datacoin.

static const uint256 hashGenesisBlockOfficial("f9f6d9a689f7a4093c71f397d8fe3fbef3a05cd6f919d51b4a9447aa22743dfb");
static const uint256 hashGenesisBlockTestNet("f9f6d9a689f7a4093c71f397d8fe3fbef3a05cd6f919d51b4a9447aa22743dfb");

  // Genesis block
        qDebug()<<"Genesis block";
        const char* pszStartTopic = "The Times 26/Dec/2013 Chancellor on brink of second bailout for banks";//https://bitcointalk.org/index.php?topic=325735.0";
        CTransaction txNew;
        txNew.vin.resize(1);
        txNew.vout.resize(1);
        txNew.vin[0].scriptSig = CScript() << 0 << CBigNum(999) << vector<unsigned char>((const unsigned char*)pszStartTopic, (const unsigned char*)pszStartTopic + strlen(pszStartTopic));
        txNew.vout[0].nValue = COIN;
        txNew.vout[0].scriptPubKey = CScript();
        CBlock block;
        block.vtx.push_back(txNew);
        block.hashPrevBlock = 0;
        block.hashMerkleRoot = block.BuildMerkleTree();
        block.nTime    = 1387977869 ;//http://www.unixtimestamp.com/index.php
        block.nBits    = TargetFromInt(6);
        block.nNonce   = 49030125;
        block.bnPrimeChainMultiplier = (uint64) 5651310;

        if (fTestNet)
        {
            block.nTime    = 1387977869 ;
            block.nBits    = TargetFromInt(4);
            block.nNonce   = 46032;
            block.bnPrimeChainMultiplier = (uint64) 211890;
        }

        //// debug print
        uint256 hash = block.GetHash();
        printf("%s\n", hash.ToString().c_str());

        qDebug()<<"hash:"<<hash.ToString().c_str();
        printf("%s\n", hashGenesisBlock.ToString().c_str());
        qDebug()<<"hashGenesisBlock:"<<hashGenesisBlock.ToString().c_str();
        printf("%s\n", block.hashMerkleRoot.ToString().c_str());
         qDebug()<<"block.hashMerkleRoot:"<<block.hashMerkleRoot.ToString().c_str();
        assert(block.hashMerkleRoot == uint256("a0c44c1b6dd50fcaa2bc1c4d7f8ca406506caee88578d751fb3824b41bc34d84"));
        block.print();

        assert(hash == hashGenesisBlock);
        {
            CValidationState state;
            assert(block.CheckBlock(state, true, true));
            assert(CheckProofOfWork(block.GetHeaderHash(), block.nBits, block.bnPrimeChainMultiplier, block.nPrimeChainType, block.nPrimeChainLength));
        }

Failed at assert(CheckProofOfWork(block.GetHeaderHash(), block.nBits, block.bnPrimeChainMultiplier, block.nPrimeChainType, block.nPrimeChainLength));. And the debug.log says:

    CBlock(hash=f9f6d9a689f7a4093c71f397d8fe3fbef3a05cd6f919d51b4a9447aa22743dfb, hashBlockHeader=7d6aeeb7ca2b87d2f48bbd7a675c8374691c4f44f0db1a10de66436bfbcb0188, ver=2, hashPrevBlock=0000000000000000000000000000000000000000000000000000000000000000, hashMerkleRoot=a0c44c1b6dd50fcaa2bc1c4d7f8ca406506caee88578d751fb3824b41bc34d84, nTime=1387977869, nBits=06000000, nNonce=49030125, vtx=1)
      CTransaction(hash=a0c44c1b6dd50fcaa2bc1c4d7f8ca406506caee88578d751fb3824b41bc34d84, ver=1, vin.size=1, vout.size=1, nLockTime=0, data.size=0)
        CTxIn(COutPoint(0000000000000000000000000000000000000000000000000000000000000000, 4294967295), coinbase 0002e703455468652054696d65732032362f4465632f32303133204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
        CTxOut(error)
ERROR: CheckPrimeProofOfWork() : block header hash under limit
ERROR: CheckProofOfWork() : check failed for prime proof-of-work

Anything else can I change to make the genesis block work?

3
  • 1
    This may belong here: bitcoin.stackexchange.com
    – punund
    Commented Dec 25, 2013 at 12:10
  • Sorry I hurry to get the answer
    – Gank
    Commented Dec 25, 2013 at 12:11
  • This question appears to be off-topic because it should be on bitcoin.stackexchange.com
    – user177800
    Commented Mar 5, 2014 at 20:36

3 Answers 3

14

You must mine the genesis block. There is no code in the most recent heads of the altcoin sources that can do the mining for you, although earlier releases of the source code would automatically create a new genesis block at that point, instead of failing the assertion. That was taken out, since it's not needed and may in fact cause more headaches for the average miner if their local db becomes unavailable.

You can try to go back in time on your source code tree to find an earlier version of the source you forked from, and try to find the code that creates the genesis block. When it runs it will try to mine a new genesis block, and when it does it will fail one more time at that assertion. You then have to put that hash and nonce into your main.h file, and do it for both your main net and test net. After that, the assertion will not fail anymore and you have the hashes for your genesis block in the code now.

Here's the code that does it, in case you can't find it in your older source..

    // If genesis block hash does not match, then generate new genesis hash.
    if (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;

        while(true)
        {
            thash = scrypt_blockhash(BEGIN(block.nVersion));
            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());

Once it finds a nonce that makes a hash that satisfies the target, it will stop and print the nonce and hash values. You need to put these new genesis block nonce and hash values into your code so that it will pass the assertions next time.

If your code is based on older (non-optimized) source code, then you won't have a function scrypt_blockhash() and you likely need to use the original functions. So change the code:

            thash = scrypt_blockhash(BEGIN(block.nVersion));

to

            static char scratchpad[SCRYPT_SCRATCHPAD_SIZE];
            scrypt_1024_1_1_256_sp(BEGIN(block.nVersion), BEGIN(thash), scratchpad);

If you do need to use the older function scrypt_1024_1_1_256_sp then you should also find the definition of SCRYPT_SCRATCHPAD_SIZE in the header files too.

Finally, all this is printed in the debug.log files. You will need to look there to find it.

Cheers!

4
  • Hey there, I'm not sure if you're still able to answer this but I've managed run this code successfully on the litecoin source however, my target is: 00000ffff0000000000000000000000000000000000000000000000000000000 I feel this is quite incorrect how do you decipher between valid and invalid targets? Commented Feb 11, 2016 at 21:21
  • I'm a little late answering, but you've probably already figured out by now that is a correct format for the target. All valid hashes for a block are going to be numerically less than ( < ) that target hash. This is why the code above searches for a genesis block hash simply by repeatedly hashing the block you created using different nonces (and eventually a new timestamp) each time through the loop.
    – Brian Onn
    Commented Feb 21, 2016 at 17:16
  • Hi, it seems newest source does not work with this solution. Do you know how to solve? Thx.
    – creator
    Commented Mar 1, 2018 at 11:34
  • chainparams.cpp:131:27: error: no match for ‘operator<=’ (operand types are ‘uint256’ and ‘uint256’) 131 | if (thash <= hashTarget) | ~~~~~ ^~ ~~~~~~~~~~ | | | | uint256 uint256 Commented Oct 28, 2021 at 12:19
4

If you want to generate our own unique genesis block you should generate and replace at least the following parameters:

  • nTime (the unix time. Your wallet will display the "No block source available 5 week(s) behind" mentioned if this is 5 weeks old from now)
  • pszTimeStamp (the "timestamp" to "justify" no premining has taken place)
  • hashMerkleRoot (the merkle root based on the coinbase transaction of the block)
  • hashGenesisBlock (the genesis hash itself!)
  • nNonce (the correct nounce which is incremented when searching for the hash that satisfies the target (=difficulty))

The pubkey in the output transaction script can also be changed to a unique value. However, as the genesis block can't be spent anyway the same pubkey can be used as in e.g. Bitcoin.

You can use this script to create the values for sha256/scrypt:

https://github.com/lhartikk/GenesisH0

There is also a faster implementation done in C but sha256 only:

https://github.com/Gnaf/GenesisBlockZero

1
  • This code based on old version. I want to know newest source(bitcoin 0.15.1) based code. Variables, positions are not match with older version.
    – creator
    Commented Feb 17, 2018 at 6:01
1

The error because your generated genesis doesn't match the proof of work algorithm. Your generated hash must be match the blockhash which satisfy the pow logic. block.GetHash() shoud be eual to hashGenesisBlock the hashGenesisBlock calculated by pow by changing the nonce parameter ,at some point you will get a hash which should satisfy the pow logic(condition)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.