ERROR: AcceptBlock: high-hash, proof of work failed (code 16)

-1

I followed this medium link to create a coin just like bitcoin . https://medium.com/@jordan.baczuk/how-to-fork-bitcoin-c39139506443

Based on this tutorial i update DEFAULT_MAX_TIP_AGE to int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE * 4000; but it does not work, i did not able to mine block but when i add -maxtipage=432000000 to my command line daemon then mining work i was able to mine genesis block . but then i thought it would be better if i can create my own geneisis block.

so i followed this link : How can I create a new Genesis Block?

I made changes to pszTimestamp, nTime and nNonce , hashGenesisBlock and hashMerkleRoot.

I was able to run the daemon without any assert issue . First i got this error

ERROR: ReadBlockFromDisk: Errors in block header at CBlockDiskPos(nFile=0, nPos=8) 2018-11-08T10:12:47Z *** Failed to read block

Then after running command line daemon with -reindex . the previous error vanishes but got a new error

ERROR: AcceptBlock: high-hash, proof of work failed (code 16)

How can i resolve this issue

EDIT: Based on the suggestion given by @JBaczuk . I used genesisgen to generate block information

https://github.com/liveblockchain/genesisgen

CMD Syntax:

./genesis [options] <pubkey> "<timestamp>" <nBits> <startNonce> <unixtime>


My CMD:

./genesis 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f "NDTV 08/Nov/2018 India Wants To Locally Manufacture, Export Bullet Train Coaches" 486604799 2083236893 1541690605


OUTPUT:

nBits: 0x1d00ffff
startNonce: 2083236893
unixtime: 1541690605

Coinbase: 04ffff001d01044c504e4454562030382f4e6f762f3230313820496e6469612057616e747320546f204c6f63616c6c79204d616e75666163747572652c204578706f72742042756c6c657420547261696e20436f6163686573

PubkeyScript: 4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac

Merkle Hash: 94b4efc7769b39ccad3ad6cebbde8ad9d74e837e19978d9acc2ae499609d895d
Byteswapped: 5d899d6099e42acc9a8d97197e834ed7d98adebbced63aadcc399b76c7efb494
Generating block...
124397 Hashes/s, Nonce 20632283897
Block found!
Hash: 000000004c7d908bd3c911a21b849d3cdca124131d2fb8a1af009698742ad672
Nonce: 2063257030
Unix time: 1541690608


Changes in code:

static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
{
const char* pszTimestamp = "NDTV 08/Nov/2018 India Wants To Locally Manufacture, Export Bullet Train Coaches";
const CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
}


...... ...... ......

genesis = CreateGenesisBlock(1541690608, 2063257030, 0x1d00ffff, 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x000000004c7d908bd3c911a21b849d3cdca124131d2fb8a1af009698742ad672"));
assert(genesis.hashMerkleRoot == uint256S("0x94b4efc7769b39ccad3ad6cebbde8ad9d74e837e19978d9acc2ae499609d895d"));


I got this assertion error:

chainparams.cpp:125: CMainParams::CMainParams(): Assertion genesis.hashMerkleRoot == uint256S("0x94b4efc7769b39ccad3ad6cebbde8ad9d74e837e19978d9acc2ae499609d895d")' failed.
Aborted (core dumped)


2Downvoted. We have many questions regarding programming issues when creating a new altcoin. I don't believe such questions benefit a general audience, and this is a Q&A site, not a place for support. Furthermore, as a learning experience, contributing to an existing project is far more valuable. – Pieter Wuille – 2018-11-09T02:36:51.083

There obviously is an audience, since there are many questions, but is stackoverflow the place for these? I have no preference, I just wonder what to suggest for help. – JBaczuk – 2018-11-09T02:43:06.353

2@PieterWuille . Inorder to contribute to existing project . i have to learn how things work in code level so i did little changes to existing bitcoin code and trying to understand the concept. – Novice Programmer – 2018-11-09T06:07:25.003

Answers

1

This is because you didn't mine the block, i.e. you didn't search for a nonce that results in a block hash less than powLimit (the initial difficulty target) defined in src/chainparams.cpp consensus.powLimit("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), for mainnet. To do this:

Serialize the block header. Concatenate (in this order, little endian, hex format) the version, previous block hash, merkle root, unix epoch time, difficulty target (bits), and nonce. Then calculate the HASH256 or the SHA256(SHA256()). If it is not less than powLimit you must change the nonce and try again, keep doing this until you are successful, this is mining.

There are scripts out there to do this, for example: https://github.com/liveblockchain/genesisgen

Update (example from question above):

Example usage of genesisgen

./genesis [options] <pubkey> "<timestamp>" <nBits> <startNonce> <unixtime>

./genesis 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f "NDTV 08/Nov/2018 India Wants To Locally Manufacture, Export Bullet Train Coaches" 486604799 2083236893 1541690605

nBits: 0x1d00ffff
startNonce: 2083236893
unixtime: 1541690605

Coinbase: 04ffff001d01044c504e4454562030382f4e6f762f3230313820496e6469612057616e747320546f204c6f63616c6c79204d616e75666163747572652c204578706f72742042756c6c657420547261696e20436f6163686573

PubkeyScript: 4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac

Merkle Hash: 94b4efc7769b39ccad3ad6cebbde8ad9d74e837e19978d9acc2ae499609d895d
Byteswapped: 5d899d6099e42acc9a8d97197e834ed7d98adebbced63aadcc399b76c7efb494
Generating block...
124397 Hashes/s, Nonce 20632283897
Block found!
Hash: 000000004c7d908bd3c911a21b849d3cdca124131d2fb8a1af009698742ad672
Nonce: 2063257030
Unix time: 1541690608


You need to use the Byteswapped merkle root and the block hash in the assertions and the newly found nonce in the genesis block creation functions.

Thanks for your answer. I will try and let you know – Novice Programmer – 2018-11-08T15:13:12.600

The genesisgen example has two nonce: startNonce and Nonce which should i use in my program – Novice Programmer – 2018-11-08T15:16:54.407

You can just use 0 as the start nonce, unless you already know the nonce :) – JBaczuk – 2018-11-08T15:23:02.327

It does not work . i got me assetion error. i have updated my question . please check – Novice Programmer – 2018-11-09T02:34:33.827

I believe the merkleroot is wrong endianess, try using the Byteswapped: 5d899d6099e42acc9a8d97197e834ed7d98adebbced63aadcc399b76c7efb494` – JBaczuk – 2018-11-09T02:46:06.310

Thanks it works . I was able to generate genesis block without any issue :) – Novice Programmer – 2018-11-09T15:12:43.820

Also please update your answer – Novice Programmer – 2018-11-09T15:14:08.690