Browse Source

No need to convert header size from 76 to 80 as miners support blob size 80.

cn
Jianping Wu 6 years ago
parent
commit
7b289b5f58
  1. 4
      src/chainparams.cpp
  2. 26
      src/primitives/block.cpp

4
src/chainparams.cpp

@ -203,9 +203,9 @@ public: @@ -203,9 +203,9 @@ public:
pchMessageStart[3] = 0xe4;
nDefaultPort = 19335;
nPruneAfterHeight = 1000;
genesis = CreateGenesisBlock(1550789769, 10030, 0x1f0fffff, 1, 500 * COIN);
genesis = CreateGenesisBlock(1550900037, 3033, 0x1f0fffff, 1, 500 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("e1f4cbc6fa8f2cc528387496120ff3aea1e4cc1e4c31f8af619d5c30a8a326f4"));
assert(consensus.hashGenesisBlock == uint256S("584a067cf7ea6daf30c351a46c6b7403d6fdc0e6e953cf7531d11eb7d834546c"));
assert(genesis.hashMerkleRoot == uint256S("3cf6c3b6da3f4058853ee70369ee43d473aca91ae8fc8f44a645beb21c392d80"));
vFixedSeeds.clear();

26
src/primitives/block.cpp

@ -23,26 +23,18 @@ uint256 CBlockHeader::GetHash() const @@ -23,26 +23,18 @@ uint256 CBlockHeader::GetHash() const
uint256 CBlockHeader::GetPoWHash() const
{
uint256 thash;
// Convert it to Cryptonight header format.
uint8_t cnHeader[76] = {};
// Bitcoin header size is 80 bytes, while CN is 76 bytes.
// To reduce it to 76, combine nVersion(4 bytes) and hashPrevBlock(32 byte)
// into 32 byte SHA2 hash.
uint8_t combineHash[32] = {};
CSHA256().Write((uint8_t*)BEGIN(nVersion), 36).Finalize(combineHash);
memcpy(cnHeader, combineHash, sizeof(combineHash));
uint32_t offset = sizeof(combineHash);
// Copy 7 bytes of hashMerkleRoot
memcpy(cnHeader + offset, BEGIN(nVersion) + 36, 7);
offset += 7;
// Convert it to Cryptonight header format, i.e. nonce at 39th byte.
uint8_t cnHeader[80] = {};
// Copy nVersion, prevblockhas, and 3 bytes of merkleroot.
memcpy(cnHeader, BEGIN(nVersion), 39);
uint32_t offset = 39;
// Copy nonce.
assert(offset == 39);
memcpy(cnHeader + offset, BEGIN(nVersion) + 76, 4);
offset += 4;
// Copy the rest of hashMerkleRoot (25 bytes)
memcpy(cnHeader + offset, BEGIN(nVersion) + 36 + 7, 25);
offset += 25;
assert(offset == 68);
// Copy remaining 29 bytes of hashMerkleRoot
memcpy(cnHeader + offset, BEGIN(nVersion) + 39, 29);
offset += 29;
assert(offset == 72);
// Copy the rest of the header (timestamp and bits).
memcpy(cnHeader + offset, BEGIN(nVersion) + 68, 8);
// Compute the CN hash.

Loading…
Cancel
Save