Merge pull request #13 from 8bitcoder/dev

Algo switch by height, algo added approach, refactorings
This commit is contained in:
nzsquirrell
2016-06-20 17:13:13 +12:00
committed by GitHub
12 changed files with 83 additions and 151 deletions
+1
View File
@@ -69,6 +69,7 @@ public:
consensus.nBlockAlgoNormalisedWorkDecayStart1 = 866000; // block where weight decay starts
consensus.nBlockAlgoNormalisedWorkDecayStart2 = 932000; // block where weight decay starts
consensus.nGeoAvgWork_Start = 1400000;
consensus.nAlgoSwitchBlock1 = 100000000;
/**
* The message start string is designed to be unlikely to occur in normal data.
+1
View File
@@ -45,6 +45,7 @@ struct Params {
int64_t nBlockAlgoNormalisedWorkDecayStart1;
int64_t nBlockAlgoNormalisedWorkDecayStart2;
int64_t nGeoAvgWork_Start;
int64_t nAlgoSwitchBlock1;
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacingV1; }
+4 -2
View File
@@ -740,8 +740,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
miningAlgo = ALGO_GROESTL;
else if (strAlgo == "skein" || strAlgo == "skeinsha2")
miningAlgo = ALGO_SKEIN;
else if (strAlgo == "q2c" || strAlgo == "qubit" || strAlgo == "yescrypt")
miningAlgo = ALGO_CPU;
else if (strAlgo == "q2c" || strAlgo == "qubit")
miningAlgo = ALGO_QUBIT;
else if (strAlgo == "yescrypt")
miningAlgo = ALGO_YESCRYPT;
else
miningAlgo = ALGO_SHA256D;
+24 -41
View File
@@ -2249,7 +2249,7 @@ void static UpdateTip(CBlockIndex *pindexNew) {
mempool.AddTransactionsUpdated(1);
LogPrintf("%s: new best=%s height=%d algo=%d (%s) log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__,
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), chainActive.Tip()->GetAlgo(), GetAlgoName(chainActive.Tip()->GetAlgo(), chainActive.Tip()->GetBlockTime()),
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), chainActive.Tip()->GetAlgo(), GetAlgoName(chainActive.Tip()->GetAlgo()),
log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx,
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()),
Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize());
@@ -2935,7 +2935,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
return state.DoS(100, error("%s : auxpow blocks are not allowed at height %d, parameters effective from %d",
__func__, pindexPrev->nHeight + 1, consensusParams.nStartAuxPow),
REJECT_INVALID, "early-auxpow-block");
// Check proof of work
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams, algo))
return state.DoS(100, error("%s: incorrect proof of work at height %d", __func__, nHeight),
@@ -2946,6 +2946,14 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
return state.Invalid(error("%s: block's timestamp is too early", __func__),
REJECT_INVALID, "time-too-old");
// Check valid algo
if ( (algo == ALGO_QUBIT) && (nHeight >= consensusParams.nAlgoSwitchBlock1) )
return state.Invalid(error("%s: invalid QUBIT block", __func__),
REJECT_INVALID, "invalid-algo");
if ( (algo == ALGO_YESCRYPT) && (nHeight < consensusParams.nAlgoSwitchBlock1) )
return state.Invalid(error("%s: invalid YESCRYPT block", __func__),
REJECT_INVALID, "invalid-algo");
if(fCheckpointsEnabled)
{
// Check that the block chain matches the known block chain up to a checkpoint
@@ -3047,17 +3055,17 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
int nAlgoCount = 1;
CBlockIndex* piPrev = pindexPrev;
int maxCount = chainparams.GetConsensus().nBlockSequentialAlgoMaxCount1;
if(chainparams.GetConsensus().nBlockSequentialAlgoMaxCount2 > maxCount)
{
maxCount = chainparams.GetConsensus().nBlockSequentialAlgoMaxCount2;
}
if(chainparams.GetConsensus().nBlockSequentialAlgoMaxCount3 > maxCount)
{
maxCount = chainparams.GetConsensus().nBlockSequentialAlgoMaxCount3;
}
// Maximum sequence count allowed
int nMaxSeqCount;
if (nHeight > chainparams.GetConsensus().nBlockSequentialAlgoRuleStart3)
nMaxSeqCount = chainparams.GetConsensus().nBlockSequentialAlgoMaxCount3;
else
if (nHeight > chainparams.GetConsensus().nBlockSequentialAlgoRuleStart2)
nMaxSeqCount = chainparams.GetConsensus().nBlockSequentialAlgoMaxCount2;
else
nMaxSeqCount = chainparams.GetConsensus().nBlockSequentialAlgoMaxCount1;
while (piPrev!=NULL && (nAlgoCount <= maxCount))
while (piPrev!=NULL && (nAlgoCount <= nMaxSeqCount))
{
if (piPrev->GetAlgo() != nAlgo)
break;
@@ -3065,38 +3073,13 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
piPrev = piPrev->pprev;
}
if (nHeight > chainparams.GetConsensus().nBlockSequentialAlgoRuleStart3)
if(fDebug)
{
if(fDebug)
{
LogPrintf("SequentialAlgoRule3 DEBUG: nHeight: %d, nAlgoCount: %d\n", nHeight, nAlgoCount);
}
if (nAlgoCount > chainparams.GetConsensus().nBlockSequentialAlgoMaxCount3)
{
return state.DoS(100, error("%s: too many blocks from same algo", __func__),REJECT_INVALID, "algo-toomany");
}
LogPrintf("SequentialAlgoRule DEBUG: nHeight: %d, nAlgoCount: %d, nMaxSeqCount: %d\n", nHeight, nAlgoCount, nMaxSeqCount);
}
else if (nHeight > chainparams.GetConsensus().nBlockSequentialAlgoRuleStart2)
if (nAlgoCount > nMaxSeqCount)
{
if(fDebug)
{
LogPrintf("SequentialAlgoRule2 DEBUG: nHeight: %d, nAlgoCount: %d\n", nHeight, nAlgoCount);
}
if (nAlgoCount > chainparams.GetConsensus().nBlockSequentialAlgoMaxCount2)
{
return state.DoS(100, error("%s: too many blocks from same algo", __func__),REJECT_INVALID, "algo-toomany");
}
}
else if (nAlgoCount > chainparams.GetConsensus().nBlockSequentialAlgoMaxCount1)
{
if(fDebug)
{
LogPrintf("SequentialAlgoRule1 DEBUG: nHeight: %d, nAlgoCount: %d\n", nHeight, nAlgoCount);
}
if (nAlgoCount > chainparams.GetConsensus().nBlockSequentialAlgoMaxCount1)
{
return state.DoS(100, error("%s: too many blocks from same algo", __func__),REJECT_INVALID, "algo-toomany");
}
return state.DoS(100, error("%s: too many blocks from same algo", __func__),REJECT_INVALID, "algo-toomany");
}
}
}
+7 -12
View File
@@ -18,7 +18,6 @@
#include "timedata.h"
#include "util.h"
#include "utilmoneystr.h"
#include "myriad_params.h"
#ifdef ENABLE_WALLET
#include "wallet/wallet.h"
#endif
@@ -811,17 +810,13 @@ void static ThreadMiner(CWallet *pwallet)
LogPrintf("MyriadMiner[Skein] miner started\n");
GenericMiner(pwallet, ALGO_SKEIN);
break;
case ALGO_CPU:
if(GetTime() >= nTimeYescryptStart)
{
LogPrintf("MyriadMiner[Yescrypt] miner started\n");
GenericMiner(pwallet, ALGO_CPU); // could be replaced with a decent yescrypt miner in the style of scrypt, but how much need?
}
else
{
LogPrintf("MyriadMiner[Qubit] miner started\n");
GenericMiner(pwallet, ALGO_CPU);
}
case ALGO_QUBIT:
LogPrintf("MyriadMiner[Qubit] miner started\n");
GenericMiner(pwallet, ALGO_QUBIT);
break;
case ALGO_YESCRYPT:
LogPrintf("MyriadMiner[Yescrypt] miner started\n");
GenericMiner(pwallet, ALGO_YESCRYPT); // could be replaced with a decent yescrypt miner in the style of scrypt, but how much need?
break;
}
}
-11
View File
@@ -1,11 +0,0 @@
// Copyright (c) 2016 The Myriad developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef MYRIAD_PARAMS_H
#define MYRIAD_PARAMS_H
const uint32_t nTimeYescryptStart = 1470009600; // block time where Qubit hash is replaced with Yescrypt (Monday, 01-Aug-16 00:00:00 UTC) ** TODO CHANGE ME **
#endif // MYRIAD_PARAMS_H
+3 -21
View File
@@ -12,7 +12,6 @@
#include "uint256.h"
#include "util.h"
#include "bignum.h"
#include "myriad_params.h"
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params, int algo)
{
@@ -123,24 +122,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
}
}
}
// change of algo from Qubit to Yescrypt
// because the difficulty of qubit will be much higher than yescrypt on change, we will return the proof-of-work limit
// once the changeover occurs, then start adjusting once nAveragingInterval blocks have occured. Will result in a short
// insta-mine, but difficulty changes will quickly take care of this.
if(pindexLast->GetBlockTime() >= nTimeYescryptStart && algo == ALGO_CPU)
{
if(pindexFirst->GetBlockTime() < nTimeYescryptStart)
{
if(fDebug)
{
LogPrintf("nTimeYescryptStart has been passed, but insufficient yescrypt blocks to calculate new target. Returning nProofOfWorkLimit\n");
}
return nProofOfWorkLimit.GetCompact();
}
}
int64_t nActualTimespan;
if (pindexLast->nHeight >= params.nBlockTimeWarpPreventStart3)
@@ -325,7 +307,7 @@ int GetAlgoWorkFactor(int algo)
return 64 * 8;
case ALGO_SKEIN:
return 4 * 6;
case ALGO_CPU:
case ALGO_QUBIT:
return 128 * 8;
default:
return 1;
@@ -427,7 +409,7 @@ arith_uint256 GetGeometricMeanPrevWork(const CBlockIndex& block)
CBigNum bnBlockWork = CBigNum(ArithToUint256(nBlockWork));
int nAlgo = block.GetAlgo();
for (int algo = 0; algo < NUM_ALGOS; algo++)
for (int algo = 0; algo < NUM_ALGOS_IMPL; algo++)
{
if (algo != nAlgo)
{
+17 -24
View File
@@ -13,7 +13,6 @@
#include "crypto/yescrypt.h"
#include "hash.h"
#include "utilstrencodings.h"
#include "myriad_params.h"
uint256 CPureBlockHeader::GetHash() const
{
@@ -36,17 +35,14 @@ uint256 CPureBlockHeader::GetPoWHash(int algo) const
return HashGroestl(BEGIN(nVersion), END(nNonce));
case ALGO_SKEIN:
return HashSkein(BEGIN(nVersion), END(nNonce));
case ALGO_CPU:
if(nTime >= nTimeYescryptStart)
{
uint256 thash;
yescrypt_hash(BEGIN(nVersion), BEGIN(thash));
return thash;
}
else
{
return HashQubit(BEGIN(nVersion), END(nNonce));
}
case ALGO_QUBIT:
return HashQubit(BEGIN(nVersion), END(nNonce));
case ALGO_YESCRYPT:
{
uint256 thash;
yescrypt_hash(BEGIN(nVersion), BEGIN(thash));
return thash;
}
}
return GetHash();
}
@@ -63,13 +59,15 @@ int GetAlgo(int nVersion)
return ALGO_GROESTL;
case BLOCK_VERSION_SKEIN:
return ALGO_SKEIN;
case BLOCK_VERSION_CPU:
return ALGO_CPU;
case BLOCK_VERSION_QUBIT:
return ALGO_QUBIT;
case BLOCK_VERSION_YESCRYPT:
return ALGO_YESCRYPT;
}
return ALGO_SHA256D;
}
std::string GetAlgoName(int Algo, uint32_t time)
std::string GetAlgoName(int Algo)
{
switch (Algo)
{
@@ -81,15 +79,10 @@ std::string GetAlgoName(int Algo, uint32_t time)
return std::string("groestl");
case ALGO_SKEIN:
return std::string("skein");
case ALGO_CPU:
if(time >= nTimeYescryptStart)
{
return std::string("yescrypt");
}
else
{
return std::string("qubit");
}
case ALGO_QUBIT:
return std::string("qubit");
case ALGO_YESCRYPT:
return std::string("yescrypt");
}
return std::string("unknown");
}
+17 -10
View File
@@ -10,12 +10,15 @@
#include "uint256.h"
enum {
ALGO_SHA256D = 0,
ALGO_SCRYPT = 1,
ALGO_GROESTL = 2,
ALGO_SKEIN = 3,
ALGO_CPU = 4,
NUM_ALGOS };
ALGO_SHA256D = 0,
ALGO_SCRYPT = 1,
ALGO_GROESTL = 2,
ALGO_SKEIN = 3,
ALGO_QUBIT = 4,
ALGO_YESCRYPT = 5,
NUM_ALGOS_IMPL };
const int NUM_ALGOS = 5;
enum
{
@@ -27,11 +30,12 @@ enum
BLOCK_VERSION_SCRYPT = (1 << 9),
BLOCK_VERSION_GROESTL = (2 << 9),
BLOCK_VERSION_SKEIN = (3 << 9),
BLOCK_VERSION_CPU = (4 << 9),
BLOCK_VERSION_QUBIT = (4 << 9),
BLOCK_VERSION_YESCRYPT = (5 << 9),
};
int GetAlgo(int nVersion);
std::string GetAlgoName(int Algo, uint32_t time);
std::string GetAlgoName(int Algo);
/**
* Encapsulate a block version. This takes care of building it up
@@ -104,8 +108,11 @@ public:
case ALGO_SKEIN:
nVersion |= BLOCK_VERSION_SKEIN;
break;
case ALGO_CPU:
nVersion |= BLOCK_VERSION_CPU;
case ALGO_QUBIT:
nVersion |= BLOCK_VERSION_QUBIT;
break;
case ALGO_YESCRYPT:
nVersion |= BLOCK_VERSION_YESCRYPT;
break;
default:
break;
+3 -10
View File
@@ -12,7 +12,6 @@
#include "rpcserver.h"
#include "sync.h"
#include "util.h"
#include "myriad_params.h"
#include <stdint.h>
@@ -109,7 +108,7 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDe
result.push_back(Pair("version", block.nVersion.GetFullVersion()));
int algo = block.GetAlgo();
result.push_back(Pair("pow_algo_id", algo));
result.push_back(Pair("pow_algo", GetAlgoName(algo, block.GetBlockTime())));
result.push_back(Pair("pow_algo", GetAlgoName(algo)));
result.push_back(Pair("pow_hash", block.GetPoWHash(algo).GetHex()));
result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
Array txs;
@@ -597,14 +596,8 @@ Value getblockchaininfo(const Array& params, bool fHelp)
obj.push_back(Pair("difficulty_scrypt", (double)GetDifficulty(NULL, ALGO_SCRYPT)));
obj.push_back(Pair("difficulty_groestl", (double)GetDifficulty(NULL, ALGO_GROESTL)));
obj.push_back(Pair("difficulty_skein", (double)GetDifficulty(NULL, ALGO_SKEIN)));
if(GetTime() >= nTimeYescryptStart)
{
obj.push_back(Pair("difficulty_yescrypt",(double)GetDifficulty(NULL, ALGO_CPU)));
}
else
{
obj.push_back(Pair("difficulty_qubit", (double)GetDifficulty(NULL, ALGO_CPU)));
}
obj.push_back(Pair("difficulty_qubit", (double)GetDifficulty(NULL, ALGO_QUBIT)));
obj.push_back(Pair("difficulty_yescrypt", (double)GetDifficulty(NULL, ALGO_YESCRYPT)));
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip())));
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
obj.push_back(Pair("pruned", fPruneMode));
+3 -10
View File
@@ -16,7 +16,6 @@
#include "rpcserver.h"
#include "util.h"
#include "validationinterface.h"
#include "myriad_params.h"
#ifdef ENABLE_WALLET
#include "wallet/wallet.h"
#endif
@@ -261,20 +260,14 @@ Value getmininginfo(const Array& params, bool fHelp)
obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize));
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
obj.push_back(Pair("pow_algo_id", miningAlgo));
obj.push_back(Pair("pow_algo", GetAlgoName(miningAlgo, GetTime())));
obj.push_back(Pair("pow_algo", GetAlgoName(miningAlgo)));
obj.push_back(Pair("difficulty", (double)GetDifficulty(NULL, miningAlgo)));
obj.push_back(Pair("difficulty_sha256d", (double)GetDifficulty(NULL, ALGO_SHA256D)));
obj.push_back(Pair("difficulty_scrypt", (double)GetDifficulty(NULL, ALGO_SCRYPT)));
obj.push_back(Pair("difficulty_groestl", (double)GetDifficulty(NULL, ALGO_GROESTL)));
obj.push_back(Pair("difficulty_skein", (double)GetDifficulty(NULL, ALGO_SKEIN)));
if(GetTime() >= nTimeYescryptStart)
{
obj.push_back(Pair("difficulty_yescrypt",(double)GetDifficulty(NULL, ALGO_CPU)));
}
else
{
obj.push_back(Pair("difficulty_qubit", (double)GetDifficulty(NULL, ALGO_CPU)));
}
obj.push_back(Pair("difficulty_qubit", (double)GetDifficulty(NULL, ALGO_QUBIT)));
obj.push_back(Pair("difficulty_yescrypt",(double)GetDifficulty(NULL, ALGO_YESCRYPT)));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1)));
// obj.push_back(Pair("networkhashps", getnetworkhashps(params, false)));
+3 -10
View File
@@ -12,7 +12,6 @@
#include "rpcserver.h"
#include "timedata.h"
#include "util.h"
#include "myriad_params.h"
#ifdef ENABLE_WALLET
#include "wallet/wallet.h"
#include "wallet/walletdb.h"
@@ -100,20 +99,14 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("connections", (int)vNodes.size()));
obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string())));
obj.push_back(Pair("pow_algo_id", miningAlgo));
obj.push_back(Pair("pow_algo", GetAlgoName(miningAlgo, GetTime())));
obj.push_back(Pair("pow_algo", GetAlgoName(miningAlgo)));
obj.push_back(Pair("difficulty", (double)GetDifficulty(NULL, miningAlgo)));
obj.push_back(Pair("difficulty_sha256d", (double)GetDifficulty(NULL, ALGO_SHA256D)));
obj.push_back(Pair("difficulty_scrypt", (double)GetDifficulty(NULL, ALGO_SCRYPT)));
obj.push_back(Pair("difficulty_groestl", (double)GetDifficulty(NULL, ALGO_GROESTL)));
obj.push_back(Pair("difficulty_skein", (double)GetDifficulty(NULL, ALGO_SKEIN)));
if(GetTime() >= nTimeYescryptStart)
{
obj.push_back(Pair("difficulty_yescrypt",(double)GetDifficulty(NULL, ALGO_CPU)));
}
else
{
obj.push_back(Pair("difficulty_qubit", (double)GetDifficulty(NULL, ALGO_CPU)));
}
obj.push_back(Pair("difficulty_qubit", (double)GetDifficulty(NULL, ALGO_QUBIT)));
obj.push_back(Pair("difficulty_yescrypt",(double)GetDifficulty(NULL, ALGO_YESCRYPT)));
obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC()));
#ifdef ENABLE_WALLET