Mining consensus to swap algo with enable window (see PR 20)

This commit is contained in:
8bitcoder
2016-06-25 15:53:58 +02:00
parent 7b4fb5eeaf
commit 8fdea8fa59
3 changed files with 44 additions and 8 deletions
+2
View File
@@ -70,6 +70,8 @@ public:
consensus.nBlockAlgoNormalisedWorkDecayStart2 = 932000; // block where weight decay starts
consensus.nGeoAvgWork_Start = 1400000;
consensus.nAlgoSwitchBlock1 = 100000000;
consensus.nMajorityEnableAlgoSwitch1 = 600;
consensus.nAlgoSwitch1EnableWindow = 2000;
/**
* The message start string is designed to be unlikely to occur in normal data.
+2
View File
@@ -46,6 +46,8 @@ struct Params {
int64_t nBlockAlgoNormalisedWorkDecayStart2;
int64_t nGeoAvgWork_Start;
int64_t nAlgoSwitchBlock1;
int nMajorityEnableAlgoSwitch1;
int nAlgoSwitch1EnableWindow;
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacingV1; }
+40 -8
View File
@@ -84,6 +84,7 @@ void EraseOrphansFor(NodeId peer);
* in the last Consensus::Params::nMajorityWindow blocks, starting at pstart and going backwards.
*/
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams);
static bool IsAlgoSwitch1Active(const CBlockIndex* pstart, const Consensus::Params& consensusParams);
static void CheckBlockIndex();
/** Constant stuff for coinbase transactions we create: */
@@ -2946,13 +2947,31 @@ 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");
// Check for algo switch 1
// Active when:
// previous YESCRYPT block was mined or;
// mining majority and fork height reached
bool bAlgoSwitch1 = false;
if (nHeight >= consensusParams.nAlgoSwitchBlock1)
{
bAlgoSwitch1 = IsAlgoSwitch1Active(pindexPrev, consensusParams);
if (!bAlgoSwitch1)
bAlgoSwitch1 =
(block.nVersion > 3) &&
IsSuperMajority(3, pindexPrev, consensusParams.nMajorityEnableAlgoSwitch1, consensusParams);
}
if (bAlgoSwitch1)
{
if (algo == ALGO_QUBIT)
return state.Invalid(error("%s: invalid QUBIT block", __func__),
REJECT_INVALID, "invalid-algo");
}
else
{
if (algo == ALGO_YESCRYPT)
return state.Invalid(error("%s: invalid YESCRYPT block", __func__),
REJECT_INVALID, "invalid-algo");
}
if(fCheckpointsEnabled)
{
@@ -3057,7 +3076,9 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
// Maximum sequence count allowed
int nMaxSeqCount;
if (nHeight > chainparams.GetConsensus().nBlockSequentialAlgoRuleStart3)
if ( (nHeight > chainparams.GetConsensus().nBlockSequentialAlgoRuleStart3) &&
(block.nVersion > 3) &&
IsSuperMajority(4, pindexPrev, chainparams.GetConsensus().nMajorityEnableAlgoSwitch1, chainparams.GetConsensus()) )
nMaxSeqCount = chainparams.GetConsensus().nBlockSequentialAlgoMaxCount3;
else
if (nHeight > chainparams.GetConsensus().nBlockSequentialAlgoRuleStart2)
@@ -3172,6 +3193,17 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned
return (nFound >= nRequired);
}
static bool IsAlgoSwitch1Active(const CBlockIndex* pstart, const Consensus::Params& consensusParams)
{
bool algoFound = false;
for (int i = 0; i < consensusParams.nAlgoSwitch1EnableWindow && !algoFound && pstart != NULL; i++)
{
if (pstart->GetAlgo() == ALGO_YESCRYPT)
algoFound = true;
pstart = pstart->pprev;
}
return (algoFound);
}
bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp)
{