Chain work modify

This commit is contained in:
myriadcoin
2014-09-24 22:18:19 +02:00
parent a7f6211208
commit cc63dc117e
2 changed files with 66 additions and 4 deletions
+27 -2
View File
@@ -559,7 +559,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
}
}
if (chainActive.Height() < BLOCK_STEALTH_START)
if (!TestNet() && (chainActive.Height() < BLOCK_STEALTH_START))
{
// allow one OP_RETURN per transaction
if (nDataOut > 1)
@@ -2437,13 +2437,36 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
// Get prev block index
CBlockIndex* pindexPrev = NULL;
int nHeight = 0;
if (hash != Params().HashGenesisBlock()) {
if (hash != Params().HashGenesisBlock())
{
// Check previous block
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
if (mi == mapBlockIndex.end())
return state.DoS(10, error("AcceptBlock() : prev block not found"), 0, "bad-prevblk");
pindexPrev = (*mi).second;
nHeight = pindexPrev->nHeight+1;
// Check count of sequence of same algo
if ( (TestNet() && (nHeight > 200))
|| (nHeight > nBlockSequentialAlgoRuleStart) )
{
int nAlgo = block.GetAlgo();
int nAlgoCount = 1;
CBlockIndex* piPrev = pindexPrev;
while (piPrev && (nAlgoCount < nBlockSequentialAlgoMaxCount))
{
if (piPrev->GetAlgo() != nAlgo)
break;
nAlgoCount++;
piPrev = piPrev->pprev;
}
if (nAlgoCount >= nBlockSequentialAlgoMaxCount)
{
return state.DoS(100, error("AcceptBlock() : too many blocks from same algo"),
REJECT_INVALID, "algo-toomany");
}
}
// Check proof of work
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, block.GetAlgo()))
return state.DoS(100, error("AcceptBlock() : incorrect proof of work"),
@@ -2481,6 +2504,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
}
}
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
/*
if (block.nVersion >= 2)
{
// if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet):
@@ -2494,6 +2518,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
REJECT_INVALID, "bad-cb-height");
}
}
*/
}
// Write block to history file
+39 -2
View File
@@ -68,7 +68,7 @@ static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 128;
static const unsigned int BLOCK_DOWNLOAD_TIMEOUT = 60;
/** Stealth addresses */
static const int BLOCK_STEALTH_START = 633800;
static const int64_t BLOCK_STEALTH_START = 633800;
#ifdef USE_UPNP
static const int fHaveUPnP = true;
@@ -688,6 +688,9 @@ enum BlockStatus {
};
const int64_t nBlockAlgoWorkWeightStart = 142000; // block where algo work weighting starts
const int64_t nBlockAlgoNormalisedWorkStart = 633800; // block where algo combined weight starts
const int64_t nBlockSequentialAlgoRuleStart = 633800; // block where sequential algo rule starts
const int nBlockSequentialAlgoMaxCount = 8; // maximum sequential blocks of same algo
/** The block chain is a tree shaped structure starting with the
* genesis block at the root, with each block potentially having multiple
@@ -823,6 +826,21 @@ public:
return (int64_t)nTime;
}
CBigNum GetPrevWorkForAlgo(int algo) const
{
CBigNum nWork;
CBlockIndex* pindex = this->pprev;
while (pindex)
{
if (pindex->GetAlgo() == algo)
{
return pindex->GetBlockWork();
}
pindex = pindex->pprev;
}
return Params().ProofOfWorkLimit(algo);
}
CBigNum GetBlockWork() const
{
CBigNum bnTarget;
@@ -863,7 +881,26 @@ public:
CBigNum GetBlockWorkAdjusted() const
{
CBigNum bnRes;
bnRes = GetBlockWork() * GetAlgoWorkFactor();
if ((TestNet() && (nHeight > 500)) ||
(nHeight >= nBlockAlgoNormalisedWorkStart))
{
// Adjusted block work is the sum of work of this block and the
// most recent work of one block of each algo
CBigNum nBlockWork = GetBlockWork();
int nAlgo = GetAlgo();
for (int algo = 0; algo < NUM_ALGOS; algo++)
{
if (algo != nAlgo)
{
nBlockWork += GetPrevWorkForAlgo(algo);
}
}
bnRes = nBlockWork / NUM_ALGOS;
}
else
{
bnRes = GetBlockWork() * GetAlgoWorkFactor();
}
return bnRes;
}