How to decrease target difficulty in bitcoin source (v0.8)

0

I have followed this video series ( https://www.youtube.com/watch?v=mDGxGYvkDEE ) to create an alt-coin by forking Litecoin v0.8, which i followed the videos and successfully created an altcoin.

Now i am trying to do the same with bitcoin (v0.8). I selected Bitcoin v0.8, because the source code is very similar to the Litecoin v0.8. Everything is working the same as in litecoin fork, except the part where i have to mine genesis block.

In Litecoin fork, it took about two minutes to mine the genesis block. But for bitcoin, its been about three days and still i haven't found the hash.

Some research that i did:

  1. Litecoin uses SCRYPT while bitcoin uses SHA-256.
  2. The difficulty can be lowered by changing block.nBits in genesis block creation code.
  3. For Bitcoin block.nBits = 0x1d00ffff; and for litecoin block.nBits = 0x1e0ffff0. From this i assume that the greater the value the lower is target.

When i change block.nBits value in bitcoin source i am able to mine genesis block quicker, but after injecting the mined genesis hash to source code, when i try to run bitcoind, it gives me an error saying, Invalid Chain, Rebuild database. In debug logs it says that Required Minimum amount of Proof of Work is not performed.

How can i adjust this check in bitcoin source, v0.8.

The genesis mining algorithm provided in video series is not working in bitcoin source because of SCRYPT. So i have added very simple code to mine the block.

    printf("Searching for genesis block...\n");
    // This will figure out a valid hash and Nonce if you're
    // creating a diffrent genesis block:

    uint256 hashTarget = CBigNum().SetCompact(block.nBits).getuint256();
    block.nNonce = 0;
    uint256 minHash = block.GetHash();

    printf("Hash Target= %s\n", hashTarget.ToString().c_str());

    while(true) {
        hash = block.GetHash();
        if(hash <= hashTarget) {
            break;
        }
        if(hash < minHash) {
            minHash = hash;         
            printf("Nonce = %d, Hash=%s\n", block.nNonce, minHash.ToString().c_str());
        }
        block.nNonce++;
    }


    hash = block.GetHash();
    printf("Nonce = %d, Hash=%s\n", block.nNonce, hash.ToString().c_str());

Asad Hayat

Posted 2019-04-08T05:59:22.517

Reputation: 11

No answers