mirror of
https://github.com/jwinterm/myriadcoin.git
synced 2026-10-18 05:51:27 +02:00
Allow algo work weighting (all algos 1)
This commit is contained in:
+4
-4
@@ -1453,7 +1453,7 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
|
||||
printf("InvalidChainFound: current best=%s height=%d log2_work=%.8g date=%s\n",
|
||||
hashBestChain.ToString().c_str(), nBestHeight, log(nBestChainWork.getdouble())/log(2.0),
|
||||
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexBest->GetBlockTime()).c_str());
|
||||
if (pindexBest && nBestInvalidWork > nBestChainWork + (pindexBest->GetBlockWork() * 6).getuint256())
|
||||
if (pindexBest && nBestInvalidWork > nBestChainWork + (pindexBest->GetBlockWorkAdjusted() * 6).getuint256())
|
||||
printf("InvalidChainFound: Warning: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.\n");
|
||||
}
|
||||
|
||||
@@ -2149,7 +2149,7 @@ bool AddToBlockIndex(CBlock& block, CValidationState& state, const CDiskBlockPos
|
||||
pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
|
||||
}
|
||||
pindexNew->nTx = block.vtx.size();
|
||||
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + pindexNew->GetBlockWork().getuint256();
|
||||
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + pindexNew->GetBlockWorkAdjusted().getuint256();
|
||||
pindexNew->nChainTx = (pindexNew->pprev ? pindexNew->pprev->nChainTx : 0) + pindexNew->nTx;
|
||||
pindexNew->nFile = pos.nFile;
|
||||
pindexNew->nDataPos = pos.nPos;
|
||||
@@ -2779,7 +2779,7 @@ bool static LoadBlockIndexDB()
|
||||
BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
|
||||
{
|
||||
CBlockIndex* pindex = item.second;
|
||||
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + pindex->GetBlockWork().getuint256();
|
||||
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + pindex->GetBlockWorkAdjusted().getuint256();
|
||||
pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx;
|
||||
if ((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_TRANSACTIONS && !(pindex->nStatus & BLOCK_FAILED_MASK))
|
||||
setBlockIndexValid.insert(pindex);
|
||||
@@ -3134,7 +3134,7 @@ string GetWarnings(string strFor)
|
||||
}
|
||||
|
||||
// Longer invalid proof-of-work chain
|
||||
if (pindexBest && nBestInvalidWork > nBestChainWork + (pindexBest->GetBlockWork() * 6).getuint256())
|
||||
if (pindexBest && nBestInvalidWork > nBestChainWork + (pindexBest->GetBlockWorkAdjusted() * 6).getuint256())
|
||||
{
|
||||
nPriority = 2000;
|
||||
strStatusBar = strRPC = _("Warning: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.");
|
||||
|
||||
+33
-1
@@ -687,6 +687,8 @@ enum BlockStatus {
|
||||
BLOCK_FAILED_MASK = 96
|
||||
};
|
||||
|
||||
const int64 nBlockAlgoWeightStart = 1000000;
|
||||
|
||||
/** The block chain is a tree shaped structure starting with the
|
||||
* genesis block at the root, with each block potentially having multiple
|
||||
* candidates to be the next block. A blockindex may have multiple pprev pointing
|
||||
@@ -775,7 +777,7 @@ public:
|
||||
}
|
||||
|
||||
int GetAlgo() const { return ::GetAlgo(nVersion); }
|
||||
|
||||
|
||||
CDiskBlockPos GetBlockPos() const {
|
||||
CDiskBlockPos ret;
|
||||
if (nStatus & BLOCK_HAVE_DATA) {
|
||||
@@ -826,6 +828,36 @@ public:
|
||||
return (CBigNum(1)<<256) / (bnTarget+1);
|
||||
}
|
||||
|
||||
int GetAlgoWorkFactor() const
|
||||
{
|
||||
if (nHeight < nBlockAlgoWeightStart)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
switch (GetAlgo())
|
||||
{
|
||||
case ALGO_SHA256D:
|
||||
return 1;
|
||||
case ALGO_SCRYPT:
|
||||
return 1;
|
||||
case ALGO_GROESTL:
|
||||
return 1;
|
||||
case ALGO_SKEIN:
|
||||
return 1;
|
||||
case ALGO_QUBIT:
|
||||
return 1;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
CBigNum GetBlockWorkAdjusted() const
|
||||
{
|
||||
CBigNum bnRes;
|
||||
bnRes = GetBlockWork() * GetAlgoWorkFactor();
|
||||
return bnRes;
|
||||
}
|
||||
|
||||
bool IsInMainChain() const
|
||||
{
|
||||
return nHeight < (int)vBlockIndexByHeight.size() && vBlockIndexByHeight[nHeight] == this;
|
||||
|
||||
Reference in New Issue
Block a user