Browse Source

Supported Cryptonight Variant 4.

cn_mining
Jianping Wu 6 years ago
parent
commit
d48d05a182
  1. 1
      src/consensus/params.h
  2. 2
      src/miner.cpp
  3. 4
      src/primitives/block.cpp
  4. 2
      src/primitives/block.h
  5. 3
      src/rpc/mining.cpp
  6. 5
      src/validation.cpp

1
src/consensus/params.h

@ -75,6 +75,7 @@ struct Params {
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; } int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
uint256 nMinimumChainWork; uint256 nMinimumChainWork;
uint256 defaultAssumeValid; uint256 defaultAssumeValid;
uint8_t GetCryptonoteMajorVersion() const { return 10; }
}; };
} // namespace Consensus } // namespace Consensus

2
src/miner.cpp

@ -175,7 +175,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashPrevBlock = pindexPrev->GetBlockHash();
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus()); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
pblock->nNonce = 0; pblock->nNonce = nHeight; // nNonce now holds the height for Cryptonight variant 4
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]); pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
CValidationState state; CValidationState state;

4
src/primitives/block.cpp

@ -48,7 +48,7 @@ uint256 CBlockHeader::GetPoWHash() const
uint256 thash; uint256 thash;
if (hashPrevBlock.IsNull()) { if (hashPrevBlock.IsNull()) {
// Genesis block // Genesis block
cn_slow_hash(BEGIN(nVersion), 80, BEGIN(thash), 2, 0, 0); cn_slow_hash(BEGIN(nVersion), 80, BEGIN(thash), 4, 0, 0);
return thash; return thash;
} }
@ -60,7 +60,7 @@ uint256 CBlockHeader::GetPoWHash() const
return thash; return thash;
} }
cryptonote::blobdata blob = cryptonote::t_serializable_object_to_blob(cnHeader); cryptonote::blobdata blob = cryptonote::t_serializable_object_to_blob(cnHeader);
cn_slow_hash(blob.data(), blob.size(), BEGIN(thash), 2, 0, 0); cn_slow_hash(blob.data(), blob.size(), BEGIN(thash), cnHeader.major_version - 6, 0, nNonce);
return thash; return thash;
} }

2
src/primitives/block.h

@ -124,6 +124,8 @@ public:
uint256 hashMerkleRoot; uint256 hashMerkleRoot;
uint32_t nTime; uint32_t nTime;
uint32_t nBits; uint32_t nBits;
// nNonce is no longer used as nonce, as the nonce is now in cnHeader.
// Repurpose it for block height used in Cryptnight variant 4.
uint32_t nNonce; uint32_t nNonce;
// CryptoNote header for emulation or merged mining // CryptoNote header for emulation or merged mining

3
src/rpc/mining.cpp

@ -477,7 +477,6 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
// Update nTime // Update nTime
UpdateTime(pblock, consensusParams, pindexPrev); UpdateTime(pblock, consensusParams, pindexPrev);
pblock->nNonce = 0;
std::set<std::string> setClientRules; std::set<std::string> setClientRules;
UniValue aRules(UniValue::VARR); UniValue aRules(UniValue::VARR);
@ -530,7 +529,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
cryptonote::block cn_block; cryptonote::block cn_block;
// block_header // block_header
// const int cn_variant = b.major_version >= 7 ? b.major_version - 6 : 0; // const int cn_variant = b.major_version >= 7 ? b.major_version - 6 : 0;
cn_block.major_version = 8; // cn variant 2 cn_block.major_version = consensusParams.GetCryptonoteMajorVersion();
cn_block.minor_version = 0; cn_block.minor_version = 0;
cn_block.timestamp = pblock->GetBlockTime(); cn_block.timestamp = pblock->GetBlockTime();
// The prev_id is used to store kevacoin block hash, as a proof of work. // The prev_id is used to store kevacoin block hash, as a proof of work.

5
src/validation.cpp

@ -1839,6 +1839,11 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
(*pindex->phashBlock == block.GetHash())); (*pindex->phashBlock == block.GetHash()));
int64_t nTimeStart = GetTimeMicros(); int64_t nTimeStart = GetTimeMicros();
// Check the height of the block is the same as its height on the blockchain.
// Note: nNonce now holds the value of height. It is no longer used as nonce.
if (block.nNonce != pindex->nHeight)
return error("%s: block height mismatch", __func__);
// Check it again in case a previous version let a bad block in // Check it again in case a previous version let a bad block in
// NOTE: We don't currently (re-)invoke ContextualCheckBlock() or // NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
// ContextualCheckBlockHeader() here. This means that if we add a new // ContextualCheckBlockHeader() here. This means that if we add a new

Loading…
Cancel
Save