Algo switch by height, algo added approach, refactorings

This commit is contained in:
8bitcoder
2016-06-19 12:58:29 +02:00
parent 145a74219f
commit f032ddaef1
9 changed files with 48 additions and 117 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.
+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)
{
+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