From f032ddaef1bef6d78b6a18b4fb22dc16dbc3090d Mon Sep 17 00:00:00 2001 From: 8bitcoder <8bitcoder@users.noreply.github.com> Date: Sun, 19 Jun 2016 12:58:29 +0200 Subject: [PATCH] Algo switch by height, algo added approach, refactorings --- src/chainparams.cpp | 1 + src/init.cpp | 6 ++-- src/main.cpp | 65 ++++++++++++++++--------------------------- src/miner.cpp | 19 +++++-------- src/myriad_params.h | 11 -------- src/pow.cpp | 24 ++-------------- src/rpcblockchain.cpp | 13 ++------- src/rpcmining.cpp | 13 ++------- src/rpcmisc.cpp | 13 ++------- 9 files changed, 48 insertions(+), 117 deletions(-) delete mode 100644 src/myriad_params.h diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 0020a4d2..236e5eb2 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -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. diff --git a/src/init.cpp b/src/init.cpp index 5e8c61e4..0f4f8d28 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -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; diff --git a/src/main.cpp b/src/main.cpp index 2d295632..86b7c11d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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"); } } } diff --git a/src/miner.cpp b/src/miner.cpp index a28caec4..7dd2cd90 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -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; } } diff --git a/src/myriad_params.h b/src/myriad_params.h deleted file mode 100644 index ea148c39..00000000 --- a/src/myriad_params.h +++ /dev/null @@ -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 - diff --git a/src/pow.cpp b/src/pow.cpp index a8454a8f..d8d9f44e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -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) { diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 67ab55a8..e1f38335 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -12,7 +12,6 @@ #include "rpcserver.h" #include "sync.h" #include "util.h" -#include "myriad_params.h" #include @@ -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)); diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 79295c41..207ac778 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -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))); diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index c3e85002..bebf79a3 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -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