Whatever I do, I am unable to mine the 1st block after the genesis block. All the while, I have assumed that I have mined the Genesis block, and I am unable to mine the 1st block using "setgenerate true" command. But, I may be wrong. I may have NOT actually mined the genesis block. Yes, I have got confused. I have generated new keys. So, here is what I have done from start.
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,
1538530667, // * 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)
500 // * estimated number of transactions per day after checkpoint
};
pchMessageStart[0] = 0x91;
pchMessageStart[1] = 0xc5;
pchMessageStart[2] = 0xfa;
pchMessageStart[3] = 0xe3;
vAlertPubKey = ParseHex("04ae6724abca5c2e2e9524d3cd10a303e0ef3f02d324bac4d06aceb873fb8591f1a968d9a2e5ac7024d5a45643d189b99015314d7ef1ff5f8799b9680d6e668471");
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("047394ed7e750f6202487e7c8ec1e61bbd2fb5cdc6f0f5488af4d2ea082bec606fea95eea381cd0466cf6ea53d8f42c299f9d0e2a3bc313515fc52f02a16fef0a0") << 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();
In the main.cpp file I changed the following
int64_t nSubsidy = 0;
if(nHeight == 0) {
nSubsidy = 0;
} else if( .......
Please note, I have also tried changing nSubsidy value for nHight = 0 to "50 * COIN" and also to higher value like "5000 * COIN". Everything results in the same issue.
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 = 1538530667
block.nNonce = 3916247
block.hashMerkleRoot: 668d1e9c1c4f354589b9357d0ac0135b5e236f13ea8cf3bdf79e3670d347e07b
block.GetHash = 00000320986bcdf6c2e62f36321232ce1dfc77dc0e0b4a79e2199d8b77fa4820
4) Updated the above info in the file "chainparams.cpp".
boost::assign::map_list_of(0, uint256("00000320986bcdf6c2e62f36321232ce1dfc77dc0e0b4a79e2199d8b77fa4820"));
genesis.nTime = 1538530667;
genesis.nBits = 0x1e0ffff0;
genesis.nNonce = 3916247;
assert(hashGenesisBlock == uint256("00000320986bcdf6c2e62f36321232ce1dfc77dc0e0b4a79e2199d8b77fa4820"));
assert(genesis.hashMerkleRoot == uint256("668d1e9c1c4f354589b9357d0ac0135b5e236f13ea8cf3bdf79e3670d347e07b"));
5) Removed the code that I used to create the genesis block which I used in step 2 (above).
6) Compiled again, no errors or issues.
7) I made this current VPS as server and created a "coin.conf" file and added the following:
server=1
rpcuser=user
rpcpassword=password
listen=1
daemon=1
8) I did NOT clone this server to create a new client. Instead, I created a new VPS, installed all the dependences and copied the full folder - complete project into that client VPS to setup the client.
9) I added the following in "coin.conf" file in the client VPS.
addnode=<ipaddress of the server> (Ex: 207.87.10.2)
10) Started the wallet - "coin-qt" on the server. No errors.
11) Started the wallet - "coin-qt" on the client. No errors.
12) Both connected without issues.
13) Ran the following command on the client to mine the 1st block.
setgenerate true
Got the following error.
"wallet keypool empty"
stopped setgenerate using
setgenerate false
14) Executed the following command.
keypoolrefill
15) Again tried setgenerate
setgenerate true
16) Checked the debug.log file. This is what I am getting.
CreateNewBlock(): total size 1000
ERROR: CheckProofOfWork() : hash doesn't match nBits
ERROR: CheckBlockHeader() : proof of work failed
ERROR: CheckBlock() : CheckBlockHeader failed
CreateNewBlock() : TestBlockValidity failed
keypool return 2
keypool reserve 2
I printed the hashes in the debug file. This is what I get.
Hash = 35301222bb9164c21222107e1c43045c50c190d63eb8be2ad193ed38228b26a1
bnTarget = 00000fffff000000000000000000000000000000000000000000000000000000
I am stuck here. Whatever I do, how many times I start from scratch, I end up here.
Are there any other setting that I have to change related to ProofOfWork? What am I doing wrong? Can someone help me?