Browse Source

Supported Cryptonight Variant 4.

cn_mining
Jianping Wu 5 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 { @@ -75,6 +75,7 @@ struct Params {
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
uint256 nMinimumChainWork;
uint256 defaultAssumeValid;
uint8_t GetCryptonoteMajorVersion() const { return 10; }
};
} // namespace Consensus

2
src/miner.cpp

@ -175,7 +175,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc @@ -175,7 +175,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
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]);
CValidationState state;

4
src/primitives/block.cpp

@ -48,7 +48,7 @@ uint256 CBlockHeader::GetPoWHash() const @@ -48,7 +48,7 @@ uint256 CBlockHeader::GetPoWHash() const
uint256 thash;
if (hashPrevBlock.IsNull()) {
// 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;
}
@ -60,7 +60,7 @@ uint256 CBlockHeader::GetPoWHash() const @@ -60,7 +60,7 @@ uint256 CBlockHeader::GetPoWHash() const
return thash;
}
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;
}

2
src/primitives/block.h

@ -124,6 +124,8 @@ public: @@ -124,6 +124,8 @@ public:
uint256 hashMerkleRoot;
uint32_t nTime;
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;
// CryptoNote header for emulation or merged mining

3
src/rpc/mining.cpp

@ -477,7 +477,6 @@ UniValue getblocktemplate(const JSONRPCRequest& request) @@ -477,7 +477,6 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
// Update nTime
UpdateTime(pblock, consensusParams, pindexPrev);
pblock->nNonce = 0;
std::set<std::string> setClientRules;
UniValue aRules(UniValue::VARR);
@ -530,7 +529,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) @@ -530,7 +529,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
cryptonote::block cn_block;
// block_header
// 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.timestamp = pblock->GetBlockTime();
// 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 @@ -1839,6 +1839,11 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
(*pindex->phashBlock == block.GetHash()));
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
// NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
// ContextualCheckBlockHeader() here. This means that if we add a new

Loading…
Cancel
Save