CACHeCoin_v_6.1.0.0
1. POS and POW are separated (retarget POW - 15min, POS - 10min)
2. A new algorithm for calculating the difficulty (VALM-Cach (logical analysis, mathematically variable))
3. Spam-Hash control function added
4. Subsidy algorithm modified (Inverted (min 45, max 90))
5. Errors in calculating the balance of addresses eliminated
6. There are other minor changes
7. I do not dwell on the changes made
Algorithm VALM-Cach passed tests..
.
getdifficulty
13:49:15
{
"proof-of- work" : 0.02867835,
"search-interval-powblock" : 505,
"search-twointerval-powblock" : 2296,
"search-full-result-powblock" : 1439,
"pow-target-spacing-variable" : 1030,
"UpperLower-pow" : 182,
"XUpper-pow" : 1,
"XLower-pow" : 104,
"proof-of-stake" : 2.95717419,
"search-interval-posblock" : 385,
"search-twointerval-posblock" : 335,
"search-full-result-posblock" : 385,
"pos-target-spacing-variable" : 670,
"UpperLower-pos" : 275,
"XUpper-pos" : 122,
"XLower-pos" : 1,
"search-interval-without pow block" : 487,
"search-interval-without pos block" : 593
}
static const int64 nTargetSpacingWorkMaxPow = 12 * nPowTargetSpacing; // 14400
static const int64 nTargetSpacingWorkMaxPos = 12 * nPosTargetSpacing; // 7200
static const int64 nTargetTimespanPow = nTargetSpacingWorkMaxPow * 6 * 12; // 1036800 matrix
static const int64 nTargetTimespanPos = nTargetSpacingWorkMaxPos * 6 * 12; // 518400 matrix
unsigned int GetNextTargetRequiredPow(const CBlockIndex* powpindexLast, bool fProofOfWork)
{
CBigNum bnTargetLimitPow = bnProofOfWorkLimit;
if (powpindexLast == NULL)
return bnTargetLimitPow.GetCompact(); // last block
const CBlockIndex* powpindexPrev = GetLastBlockIndexPow(powpindexLast, fProofOfWork);
if (powpindexPrev->pprev == NULL)
return bnInitialHashTarget.GetCompact(); // first block
const CBlockIndex* powpindexPrevPrev = GetLastBlockIndexPow(powpindexPrev->pprev, fProofOfWork);
if (powpindexPrevPrev->pprev == NULL)
return bnInitialHashTarget.GetCompact(); // second block 1
const CBlockIndex* powpindexPrevPrevPrev = GetLastBlockIndexPow(powpindexPrevPrev->pprev, fProofOfWork);
if (powpindexPrevPrevPrev->pprev == NULL)
return bnInitialHashTarget.GetCompact(); // second block 2
const CBlockIndex* powpindexPrevPrevPrevPrev = GetLastBlockIndexPow(powpindexPrevPrevPrev->pprev, fProofOfWork);
if (powpindexPrevPrevPrevPrev->pprev == NULL)
return bnInitialHashTarget.GetCompact(); // second block 3
const CBlockIndex* powpindexPrevPrevPrevPrevPrev = GetLastBlockIndexPow(powpindexPrevPrevPrevPrev->pprev, fProofOfWork);
if (powpindexPrevPrevPrevPrevPrev->pprev == NULL)
return bnInitialHashTarget.GetCompact(); // second block 4
const CBlockIndex* powpindexPrevPrevPrevPrevPrevPrev = GetLastBlockIndexPow(powpindexPrevPrevPrevPrevPrev->pprev, fProofOfWork);
if (powpindexPrevPrevPrevPrevPrevPrev->pprev == NULL)
return bnInitialHashTarget.GetCompact(); // second block 5
double nPowTargetSpacingTest = 0;
if(powpindexPrev->GetBlockTime() > nPowForceTimestamp && powpindexPrev->GetBlockTime() < nPowForceTimestamp + NTest)
nPowTargetSpacingTest = nPowTargetSpacing / nPowTargetSpacing * 900;
else
nPowTargetSpacingTest = nPowTargetSpacing;
int64 nActualTimeIntervalLongPowVeryFirst = powpindexPrev->GetBlockTime() - powpindexPrevPrev->GetBlockTime();
int64 nActualTimeIntervalLongPowFirst = powpindexPrevPrev->GetBlockTime() - powpindexPrevPrevPrev->GetBlockTime();
int64 nActualTimeIntervalLongPowSecond = powpindexPrevPrevPrev->GetBlockTime() - powpindexPrevPrevPrevPrev->GetBlockTime();
double nActualSpacingTotalsPow = ( nActualTimeIntervalLongPowVeryFirst + nActualTimeIntervalLongPowFirst ) / 2;
double nActualTimeIntervalNvar = nActualTimeIntervalLongPowVeryFirst; // ( nActualSpacingTotalsPow + nActualTimeIntervalLongPowSecond ) / 2;
// cachecoin retarget
// VALM-Cach /logical analysis - mathematically variable/
int64 nActualSpacingPow = 0;
double nVar = nPowTargetSpacingTest / 3;
int64 nNonAccelerating = 0; // sec +0-
PowPindexPrevTime = powpindexPrev->GetBlockTime();
nLastCoinPowSearchInterval = nActualTimeIntervalLongPowVeryFirst;
nLastCoinPowFiveInterval = nActualSpacingTotalsPow;
nActualSpacingPow = ( nActualSpacingTotalsPow + nActualTimeIntervalLongPowSecond ) / 2; // nActualTimeIntervalLongPowVeryFirst;
if(nActualTimeIntervalNvar >= nNonAccelerating && nActualTimeIntervalNvar < nPowTargetSpacingTest - nNonAccelerating)
nPowTargetSpacingVar = (( nPowTargetSpacingTest - 1 + nVar ) - ( nActualTimeIntervalNvar * nVar / nPowTargetSpacingTest ));
else if
(nActualTimeIntervalNvar > nPowTargetSpacingTest + nNonAccelerating && nActualTimeIntervalNvar <= nPowTargetSpacingTest * 2)
nPowTargetSpacingVar = (( nPowTargetSpacingTest + 1 + nVar ) - ( nActualTimeIntervalNvar * nVar / nPowTargetSpacingTest ));
else if
(nActualTimeIntervalNvar > nPowTargetSpacingTest * 2)
nPowTargetSpacingVar = nPowTargetSpacingTest - nVar + 1;
else
nPowTargetSpacingVar = nPowTargetSpacingTest;
double nPTSp = nPowTargetSpacingTest; // 1200 sec
int64 powUppermin = 0;
double powUppermax = nPTSp - nNonAccelerating; // 1199 sec
double powLowermin = nPTSp + nNonAccelerating; // 1201 sec
int64 powLowermax = nTargetSpacingWorkMaxPow; // 14400 sec
if(nActualTimeIntervalLongPowVeryFirst > powLowermin && nActualSpacingTotalsPow < powUppermax)
nActualTimeIntervalXUXLpow = nActualTimeIntervalLongPowVeryFirst;
else if(nActualTimeIntervalLongPowVeryFirst > powLowermin && nActualSpacingTotalsPow > powLowermin)
nActualTimeIntervalXUXLpow = min((double) nActualTimeIntervalLongPowVeryFirst, (double) nActualSpacingTotalsPow);
else if(nActualTimeIntervalLongPowVeryFirst < powUppermax && nActualSpacingTotalsPow < powUppermax)
nActualTimeIntervalXUXLpow = max((double) nActualTimeIntervalLongPowVeryFirst, (double) nActualSpacingTotalsPow);
else if(nActualSpacingTotalsPow < powUppermax && nActualSpacingTotalsPow > nActualSpacingPow)
nActualTimeIntervalXUXLpow = nActualSpacingTotalsPow;
else if(nActualSpacingTotalsPow > powLowermin && nActualSpacingTotalsPow < nActualSpacingPow)
nActualTimeIntervalXUXLpow = nActualSpacingTotalsPow;
else
nActualTimeIntervalXUXLpow = nActualSpacingPow;
double nNix = nPTSp / 100 * 70; // 714
double nReverseEffectPow = 0;
if(nActualTimeIntervalXUXLpow < nNix)
nReverseEffectPow = nActualTimeIntervalXUXLpow / nNix;
else if(nActualTimeIntervalXUXLpow > nPTSp && nActualTimeIntervalXUXLpow <= nPTSp + ( nPTSp - nNix))
nReverseEffectPow = ( nPTSp / nPTSp ) / 2;
else if(nActualTimeIntervalXUXLpow > nPTSp + ( nPTSp - nNix) && nActualTimeIntervalXUXLpow < powLowermax)
nReverseEffectPow = (( nPTSp + ( nPTSp - nNix )) / nActualTimeIntervalXUXLpow ) / 2;
else
nReverseEffectPow = 1;
powUpperLower = ( nPTSp / 2 ) * nReverseEffectPow; // interval sampling 2:1 variable
if(nActualSpacingTotalsPow < nNix / 1.30 && nActualTimeIntervalLongPowVeryFirst < powUppermax)
powUpperLower = powUpperLower * (( nNix / 1.30 ) / nActualSpacingTotalsPow );
double XUXL = nPowTargetSpacingTest / 100 * 4;
double U = 0;
double L = 0;
double XU = XUXL + ( powUppermax * powUpperLower / nPTSp ); // 100.9166 +%
double XL = XUXL + ( nPTSp * powUpperLower / powLowermin ); // 100.9167 +%
double nBalance = 1.0;
double nN = XUXL - ( XUXL / nBalance );
int64 nTargetTimespanMin = nTargetTimespanPow / XL - 1; // min
int64 nActualTimeIntervalXU = nActualTimeIntervalXUXLpow;
int64 nActualTimeIntervalXL = nActualTimeIntervalXUXLpow;
if(nActualTimeIntervalXU >= powUppermin && nActualTimeIntervalXU < powUppermax)
U = nN + (( XU - ( nActualTimeIntervalXU * powUpperLower / nPTSp )) / nBalance );
else U = 1;
if(nActualTimeIntervalXL > powLowermin && nActualTimeIntervalXL < powLowermax)
L = XL - ( nPTSp * powUpperLower / nActualTimeIntervalXL );
else if(nActualTimeIntervalXL >= powLowermax)
L = XL / 2;
else L = 1;
int64 nTargetTimespanControlu = nTargetTimespanPow / U; // min
int64 nTargetTimespanControll = nTargetTimespanPow / L; // min
if(nTargetTimespanControlu >= nTargetTimespanMin)
XUpperPow = U;
else if(nTargetTimespanControlu < nTargetTimespanMin)
XUpperPow = XU;
else
XUpperPow = 1;
if(nTargetTimespanControll >= nTargetTimespanMin)
XLowerPow = L;
else if(nTargetTimespanControll < nTargetTimespanMin)
XLowerPow = XL;
else
XLowerPow = 1;
CBigNum bnNewPow;
bnNewPow.SetCompact(powpindexPrev->nBits);
double nTargetTimespanBn = nTargetTimespanPow / max( XUpperPow, XLowerPow );
double nInterval = nTargetTimespanBn / nPowTargetSpacingTest;
if(powpindexPrev->GetBlockTime() > nPowForceTimestamp)
{
if(powpindexPrev->GetBlockTime() > nPowForceTimestamp && powpindexPrev->IsProofOfWork())
bnNewPow *= (( (int64) nInterval - 1) * (int64) nPowTargetSpacingVar + (int64) nActualTimeIntervalXUXLpow + (int64) nActualTimeIntervalXUXLpow);
bnNewPow /= (( (int64) nInterval + 1) * (int64) nPowTargetSpacingVar);
if(bnNewPow > bnTargetLimitPow)
bnNewPow = bnTargetLimitPow;
if(bnNewPow < bnTargetLimitPow + bnTargetLimitPow &&
powpindexPrev->GetBlockTime() > nPowForceTimestamp &&
powpindexPrev->GetBlockTime() < nPowForceTimestamp + NTest)
bnNewPow = bnTargetLimitPow;
}
return bnNewPow.GetCompact();
}