Browse Source

Changed block hash calculation, used cryptonote header instead.

cn_mining
Jianping Wu 5 years ago
parent
commit
68ffbfc104
  1. 8
      src/chainparams.cpp
  2. 15
      src/primitives/block.cpp
  3. 4
      src/primitives/block.h
  4. 4
      src/rpc/blockchain.cpp

8
src/chainparams.cpp

@ -36,7 +36,7 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi
genesis.hashMerkleRoot = BlockMerkleRoot(genesis); genesis.hashMerkleRoot = BlockMerkleRoot(genesis);
genesis.cnHeader.major_version = 10; // Cryptonight variant 4 genesis.cnHeader.major_version = 10; // Cryptonight variant 4
genesis.cnHeader.prev_id = genesis.GetHash(); genesis.cnHeader.prev_id = genesis.GetOriginalBlockHash();
genesis.cnHeader.nonce = nNonce; genesis.cnHeader.nonce = nNonce;
return genesis; return genesis;
} }
@ -120,7 +120,7 @@ public:
//TODO: target: 0x1e0fffff, update timestampe and nonce. //TODO: target: 0x1e0fffff, update timestampe and nonce.
genesis = CreateGenesisBlock(1553145843, 6146, 0x1f0ffff0, 1, genesisBlockReward); genesis = CreateGenesisBlock(1553145843, 6146, 0x1f0ffff0, 1, genesisBlockReward);
consensus.hashGenesisBlock = genesis.GetHash(); consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x8bc96b56465c9aa5f6511c4d2fca2f6bf6ae67b9c9553272908ae511d59e9b77")); assert(consensus.hashGenesisBlock == uint256S("0xbad6e50683aa6032b9ea9bbbc67a6b4621612221176b963fc9ce9ae10a77effd"));
assert(genesis.hashMerkleRoot == uint256S("0xb21d4680875c0e472b7dbf3dbab2aaeb2dbbb5fa8b154f978b5ea0706d1fd5b9")); assert(genesis.hashMerkleRoot == uint256S("0xb21d4680875c0e472b7dbf3dbab2aaeb2dbbb5fa8b154f978b5ea0706d1fd5b9"));
// Note that of those with the service bits flag, most only support a subset of possible options // Note that of those with the service bits flag, most only support a subset of possible options
@ -226,7 +226,7 @@ public:
printf("new testnet genesis hash: %s\n", genesis.GetHash().ToString().c_str()); printf("new testnet genesis hash: %s\n", genesis.GetHash().ToString().c_str());
} }
#endif #endif
assert(consensus.hashGenesisBlock == uint256S("cb3c982e8c3d3f7d03b745ba9c511d0a586045b4170c977a72883d3277bdd5e6")); assert(consensus.hashGenesisBlock == uint256S("f1b4d0460060c2cdfe4be2e71c15f23338b262b72dfa73c389cc144896a453ec"));
assert(genesis.hashMerkleRoot == uint256S("3cf6c3b6da3f4058853ee70369ee43d473aca91ae8fc8f44a645beb21c392d80")); assert(genesis.hashMerkleRoot == uint256S("3cf6c3b6da3f4058853ee70369ee43d473aca91ae8fc8f44a645beb21c392d80"));
vFixedSeeds.clear(); vFixedSeeds.clear();
@ -315,7 +315,7 @@ public:
genesis = CreateGenesisBlock(1553147907, 6, 0x207fffff, 1, 50 * COIN); genesis = CreateGenesisBlock(1553147907, 6, 0x207fffff, 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash(); consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x193385e60d04db90e30332508d97401ec3568ee2fe765b279fd9b3e4b0b78ca5")); assert(consensus.hashGenesisBlock == uint256S("0x16c9c15caf4524e61004fcd4feb2217818b8884d4ad9b8769f5ea6c62c69097e"));
assert(genesis.hashMerkleRoot == uint256S("0x13ec98c3307b8e6b67b91c605c7347916a99f9dfde7b5d88365aaef322192314")); assert(genesis.hashMerkleRoot == uint256S("0x13ec98c3307b8e6b67b91c605c7347916a99f9dfde7b5d88365aaef322192314"));
vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds. vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.

15
src/primitives/block.cpp

@ -15,23 +15,16 @@
extern "C" void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed, uint64_t height); extern "C" void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed, uint64_t height);
extern "C" void cn_fast_hash(const void *data, size_t length, char *hash); extern "C" void cn_fast_hash(const void *data, size_t length, char *hash);
uint256 CBlockHeader::GetHash() const uint256 CBlockHeader::GetOriginalBlockHash() const
{ {
CHashWriter hashWriter(SER_GETHASH, PROTOCOL_VERSION); CHashWriter hashWriter(SER_GETHASH, PROTOCOL_VERSION);
hashWriter.write(BEGIN(nVersion), 80); hashWriter.write(BEGIN(nVersion), 80);
return hashWriter.GetHash(); return hashWriter.GetHash();
} }
uint256 CBlockHeader::GetCryptonoteFastHash() const uint256 CBlockHeader::GetHash() const
{ {
uint256 thash; uint256 thash;
// prev_id of CN header is used to store the kevacoin block hash.
// The value of prev_id and block hash must be the same to prove
// that PoW has been properly done.
if (GetHash() != cnHeader.prev_id) {
memset(thash.begin(), 0xff, thash.size());
return thash;
}
cryptonote::blobdata blob = cryptonote::t_serializable_object_to_blob(cnHeader); cryptonote::blobdata blob = cryptonote::t_serializable_object_to_blob(cnHeader);
cn_fast_hash(blob.data(), blob.size(), BEGIN(thash)); cn_fast_hash(blob.data(), blob.size(), BEGIN(thash));
return thash; return thash;
@ -43,7 +36,7 @@ uint256 CBlockHeader::GetPoWHash() const
// prev_id of CN header is used to store the kevacoin block hash. // prev_id of CN header is used to store the kevacoin block hash.
// The value of prev_id and block hash must be the same to prove // The value of prev_id and block hash must be the same to prove
// that PoW has been properly done. // that PoW has been properly done.
if (GetHash() != cnHeader.prev_id) { if (GetOriginalBlockHash() != cnHeader.prev_id) {
memset(thash.begin(), 0xff, thash.size()); memset(thash.begin(), 0xff, thash.size());
return thash; return thash;
} }
@ -56,7 +49,7 @@ std::string CBlock::ToString() const
{ {
std::stringstream s; std::stringstream s;
s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n", s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
GetHash().ToString(), GetOriginalBlockHash().ToString(),
nVersion, nVersion,
hashPrevBlock.ToString(), hashPrevBlock.ToString(),
hashMerkleRoot.ToString(), hashMerkleRoot.ToString(),

4
src/primitives/block.h

@ -168,9 +168,9 @@ public:
return (nBits == 0); return (nBits == 0);
} }
uint256 GetHash() const; uint256 GetOriginalBlockHash() const;
uint256 GetCryptonoteFastHash() const; uint256 GetHash() const;
uint256 GetPoWHash() const; uint256 GetPoWHash() const;

4
src/rpc/blockchain.cpp

@ -763,7 +763,7 @@ UniValue getlastblockheader(const JSONRPCRequest& request)
blockHeader.push_back(Pair("height", (uint64_t)pblockindex->nHeight)); blockHeader.push_back(Pair("height", (uint64_t)pblockindex->nHeight));
const uint64_t depth = chainActive.Height() - pblockindex->nHeight + 1; // Same as confirmations. const uint64_t depth = chainActive.Height() - pblockindex->nHeight + 1; // Same as confirmations.
blockHeader.push_back(Pair("depth", (uint64_t)depth)); blockHeader.push_back(Pair("depth", (uint64_t)depth));
blockHeader.push_back(Pair("hash", block.GetCryptonoteFastHash().GetHex())); blockHeader.push_back(Pair("hash", block.GetHash().GetHex()));
blockHeader.push_back(Pair("difficulty", GetDifficulty(pblockindex))); blockHeader.push_back(Pair("difficulty", GetDifficulty(pblockindex)));
// TODO: implement cumulative_difficulty // TODO: implement cumulative_difficulty
@ -846,7 +846,7 @@ UniValue getblockheaderbyheight(const JSONRPCRequest& request)
blockHeader.push_back(Pair("height", (uint64_t)pblockindex->nHeight)); blockHeader.push_back(Pair("height", (uint64_t)pblockindex->nHeight));
const uint64_t depth = chainActive.Height() - nHeight + 1; // Same as confirmations. const uint64_t depth = chainActive.Height() - nHeight + 1; // Same as confirmations.
blockHeader.push_back(Pair("depth", (uint64_t)depth)); blockHeader.push_back(Pair("depth", (uint64_t)depth));
blockHeader.push_back(Pair("hash", block.GetCryptonoteFastHash().GetHex())); blockHeader.push_back(Pair("hash", block.GetHash().GetHex()));
blockHeader.push_back(Pair("difficulty", GetDifficulty(pblockindex))); blockHeader.push_back(Pair("difficulty", GetDifficulty(pblockindex)));
// TODO: implement cumulative_difficulty // TODO: implement cumulative_difficulty

Loading…
Cancel
Save