-
Notifications
You must be signed in to change notification settings - Fork 709
SHA256 Mining On Testnet #1259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
SHA256 Mining On Testnet #1259
Changes from all commits
1d3a69d
76b4977
57b6f07
b997155
0cb2737
3fdea86
4510e50
b291da9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ static const uint32_t TESTNET_X16RV2ACTIVATIONTIME = 1567533600; | |
| static const uint32_t REGTEST_X16RV2ACTIVATIONTIME = 1569931200; | ||
|
|
||
| uint32_t nKAWPOWActivationTime; | ||
| uint32_t nSHA256KawpowSwitchActivationTime; | ||
| bool fKawpowAsMiningAlgo; | ||
|
|
||
| BlockNetwork bNetwork = BlockNetwork(); | ||
|
|
||
|
|
@@ -37,45 +39,65 @@ void BlockNetwork::SetNetwork(const std::string& net) | |
|
|
||
| uint256 CBlockHeader::GetHash() const | ||
| { | ||
| // Check if we are before the Kawpow activation time | ||
| if (nTime < nKAWPOWActivationTime) { | ||
| uint32_t nTimeToUse = MAINNET_X16RV2ACTIVATIONTIME; | ||
|
|
||
| if (bNetwork.fOnTestnet) { | ||
| nTimeToUse = TESTNET_X16RV2ACTIVATIONTIME; | ||
| } else if (bNetwork.fOnRegtest) { | ||
| nTimeToUse = REGTEST_X16RV2ACTIVATIONTIME; | ||
| } | ||
|
|
||
| // Use X16RV2 or X16R before Kawpow activation | ||
| if (nTime >= nTimeToUse) { | ||
| return HashX16RV2(BEGIN(nVersion), END(nNonce), hashPrevBlock); | ||
| } | ||
|
|
||
| return HashX16R(BEGIN(nVersion), END(nNonce), hashPrevBlock); | ||
| } else { | ||
| return KAWPOWHash_OnlyMix(*this); | ||
| // Kawpow activation time has passed, now check if we are on the testnet | ||
| if (bNetwork.fOnTestnet && !fKawpowAsMiningAlgo && nTime >= nSHA256KawpowSwitchActivationTime) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would extract this logic into a helper method. |
||
| // If on testnet and Kawpow is disabled, use SerializeHash (CPU-friendly) | ||
| return SerializeHash(*this); | ||
| } else { | ||
| // Otherwise, use Kawpow (mainnet or regtest, or Kawpow on testnet) | ||
| return KAWPOWHash_OnlyMix(*this); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| uint256 CBlockHeader::GetHashFull(uint256& mix_hash) const | ||
| { | ||
| // Check if we are before the Kawpow activation time | ||
| if (nTime < nKAWPOWActivationTime) { | ||
| uint32_t nTimeToUse = MAINNET_X16RV2ACTIVATIONTIME; | ||
|
|
||
| if (bNetwork.fOnTestnet) { | ||
| nTimeToUse = TESTNET_X16RV2ACTIVATIONTIME; | ||
| } else if (bNetwork.fOnRegtest) { | ||
| nTimeToUse = REGTEST_X16RV2ACTIVATIONTIME; | ||
| } | ||
|
|
||
| // Use X16RV2 or X16R before Kawpow activation | ||
| if (nTime >= nTimeToUse) { | ||
| return HashX16RV2(BEGIN(nVersion), END(nNonce), hashPrevBlock); | ||
| } | ||
|
|
||
| return HashX16R(BEGIN(nVersion), END(nNonce), hashPrevBlock); | ||
| } else { | ||
| return KAWPOWHash(*this, mix_hash); | ||
| // Kawpow activation time has passed, now check if we are on the testnet | ||
| if (bNetwork.fOnTestnet && !fKawpowAsMiningAlgo && nTime >= nSHA256KawpowSwitchActivationTime) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would extract this logic into a helper method. |
||
| // If on testnet and Kawpow is disabled, use SerializeHash (CPU-friendly) | ||
| return SerializeHash(*this); | ||
| } else { | ||
| // Otherwise, use Kawpow (mainnet or regtest, or Kawpow on testnet) | ||
| return KAWPOWHash(*this, mix_hash); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| uint256 CBlockHeader::GetX16RHash() const | ||
| { | ||
| return HashX16R(BEGIN(nVersion), END(nNonce), hashPrevBlock); | ||
|
|
@@ -86,6 +108,11 @@ uint256 CBlockHeader::GetX16RV2Hash() const | |
| return HashX16RV2(BEGIN(nVersion), END(nNonce), hashPrevBlock); | ||
| } | ||
|
|
||
| uint256 CBlockHeader::GetSerializeHash() const | ||
| { | ||
| return SerializeHash(*this); // Use standard SHA256 mining | ||
| } | ||
|
|
||
| /** | ||
| * @brief This takes a block header, removes the nNonce64 and the mixHash. Then performs a serialized hash of it SHA256D. | ||
| * This will be used as the input to the KAAAWWWPOW hashing function | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ | |
| */ | ||
|
|
||
| extern uint32_t nKAWPOWActivationTime; | ||
| extern uint32_t nSHA256KawpowSwitchActivationTime; | ||
| extern bool fKawpowAsMiningAlgo; // declared global here but value is set in chainparams.cpp | ||
|
|
||
| class BlockNetwork | ||
| { | ||
|
|
@@ -64,7 +66,8 @@ class CBlockHeader | |
| READWRITE(hashMerkleRoot); | ||
| READWRITE(nTime); | ||
| READWRITE(nBits); | ||
| if (nTime < nKAWPOWActivationTime) { | ||
| //If the time is before the kawpow activation time OR (on testnet, kawpow is not set as the mining algo, and past the sha256 switch activation time) | ||
| if (nTime < nKAWPOWActivationTime || (bNetwork.fOnTestnet && !fKawpowAsMiningAlgo && nTime >= nSHA256KawpowSwitchActivationTime)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would extract this logic into a helper method. |
||
| READWRITE(nNonce); | ||
| } else { | ||
| READWRITE(nHeight); | ||
|
|
@@ -95,6 +98,7 @@ class CBlockHeader | |
| uint256 GetHash() const; | ||
| uint256 GetX16RHash() const; | ||
| uint256 GetX16RV2Hash() const; | ||
| uint256 GetSerializeHash() const; | ||
|
|
||
| uint256 GetHashFull(uint256& mix_hash) const; | ||
| uint256 GetKAWPOWHeaderHash() const; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would extract this logic into a helper method.