Help needed while studying PIVX! ( hash doesn't match nBits, proof of work failed)
I am studying how a blockchain works and I have successfully forked and generated a genesis block for PIVX. I am stuck at a point and connot get past this. The process was as follows:
1) Code before genesis block:
In "chainparams.php", I have updated the following.
boost::assign::map_list_of(0, uint256("0x01"));
static const Checkpoints::CCheckpointData data = {
&mapCheckpoints,
1544789657, // * UNIX timestamp of last checkpoint block
0, // * total number of transactions between genesis and last checkpoint
// (the tx=... number in the SetBestChain debug.log lines)
2000 // * estimated number of transactions per day after checkpoint
};
pchMessageStart[0] = 0xd1;
pchMessageStart[1] = 0xb2;
pchMessageStart[2] = 0xa4;
pchMessageStart[3] = 0xe9;
vAlertPubKey = ParseHex("040155710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9");
const char* pszTimestamp = "my new message here. trying to learn how to create an altcoin.";
txNew.vout[0].nValue = 50 * COIN;
txNew.vout[0].scriptPubKey = CScript() << ParseHex("043384710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9") << OP_CHECKSIG;
genesis.nTime = 1538530667;
genesis.nBits = 0x1e0ffff0;
assert(hashGenesisBlock == uint256("0x01"));
assert(genesis.hashMerkleRoot == uint256("0x01"));
fRequireRPCPassword = false;
fMiningRequiresPeers = false;
fAllowMinDifficultyBlocks = false;
fDefaultConsistencyChecks = false;
fRequireStandard = true;
fMineBlocksOnDemand = true;
fSkipProofOfWorkCheck = false;
fTestnetToBeDeprecatedFieldRPC = false;
fHeadersFirstSyncingActive = false;
vFixedSeeds.clear();
vSeeds.clear();
2) Used the following code to create the genesis block.
if(genesis.GetHash() != uint256("0x"))
{
printf("MSearching for genesis block...\n");
uint256 hashTarget;
hashTarget.SetCompact(genesis.nBits);
while(uint256(genesis.GetHash()) > uint256(hashTarget))
{
++genesis.nNonce;
if (genesis.nNonce == 0)
{
printf("Mainnet NONCE WRAPPED, incrementing time");
std::cout << std::string("Mainnet NONCE WRAPPED, incrementing time:\n");
++genesis.nTime;
}
if (genesis.nNonce % 10000 == 0)
{
printf("Mainnet: nonce %08u: hash = %s \n", genesis.nNonce, genesis.GetHash().ToString().c_str());
}
}
printf("Mainnet block.nTime = %u \n", genesis.nTime);
printf("Mainnet block.nNonce = %u \n", genesis.nNonce);
printf("Mainnet block.hashMerkleRoot: %s\n", genesis.hashMerkleRoot.ToString().c_str());
printf("Mainnet block.GetHash = %s\n", genesis.GetHash().ToString().c_str());
}
3) I got the following results.
block.nTime = 1544789657 block.nNonce = 6204937 block.hashMerkleRoot: 2c0c073aec1ee62fda46605d1aa9c693f5987b7fbc8f2c38886fe97f9e71be56 block.GetHash = 00000f93dd64fe418016f675953d2c41372c576cb42131c33fe7531bc8661c9c
4) Updated the above info in the file "chainparams.cpp".
boost::assign::map_list_of(0, uint256("00000f93dd64fe418016f675953d2c41372c576cb42131c33fe7531bc8661c9c"));
genesis.nTime = 1544789657
genesis.nBits = 0x1e0ffff0;
genesis.nNonce = 6204937
assert(hashGenesisBlock == uint256("0x00000f93dd64fe418016f675953d2c41372c576cb42131c33fe7531bc8661c9c"));
assert(genesis.hashMerkleRoot == uint256("0x2c0c073aec1ee62fda46605d1aa9c693f5987b7fbc8f2c38886fe97f9e71be56"));
5) Removed the code that I used to create the genesis block which I used in step 2 (above).
6) Compiled again, no errors.
7) Ran the following command on the client to mine the 1st block.
Got an error:
error: {"code":-32603,"message":"Wallet keypool empty"}
8) Checked the debug.log file. This is what I am getting.
2018-12-26 09:45:52 CreateNewBlock(): total size 1000 2018-12-26 09:45:52 ERROR: CheckProofOfWork() : hash doesn't match nBits 2018-12-26 09:45:52 ERROR: CheckBlockHeader() : proof of work failed 2018-12-26 09:45:52 ERROR: CheckBlock() : CheckBlockHeader failed 2018-12-26 09:45:52 CreateNewBlock() : TestBlockValidity failed 2018-12-26 09:45:52 keypool return 2 2018-12-26 09:46:05 keypool reserve 2
I printed the hashes in the debug file and the result was as follows:
Hash = be34723aae850d487eec2f777bc15f1433afac4b312ac88dc92a5ca78cf66ced
bnTarget = 00000fffff000000000000000000000000000000000000000000000000000000
How do I get the PoW to work? Any help would be appreciated. Thanks.
http://bit.ly/2SmnXl8
Comments
Post a Comment