Skip to content

Commit

Permalink
correct fork propogation, speed up sync considerably
Browse files Browse the repository at this point in the history
  • Loading branch information
barrystyle committed Jun 5, 2019
1 parent 398d04e commit 618bcd4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
10 changes: 2 additions & 8 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,7 @@ bool static ScanHash (MinerInfo* miner, const CBlockHeader *pblock, uint32_t& nN
{
nNonce++;
block.nNonce = nNonce;
if(IsYesPower())
*phash = block.GetHashYespower();
else
*phash = block.GetHashArgon2d();
*phash = block.GetHashYespower();
miner->nHashes += 1;

if (((uint16_t*)phash)[15] <= 32)
Expand Down Expand Up @@ -706,10 +703,7 @@ void static URXMiner(MinerInfo* miner, const CChainParams& chainparams)
pblock->nNonce = nNonce;
LogPrintf("UraniumX Miner: proof-of-work found \n hash: %s \ntarget: %s\n",
hash.GetHex(), hashTarget.GetHex());
if(IsYesPower())
assert(hash == pblock->GetHashYespower());
else
assert(hash == pblock->GetHashArgon2d());
assert(hash == pblock->GetHashYespower());
SetThreadPriority (THREAD_PRIORITY_NORMAL);
fBlockFound = ProcessBlockFound(pblock, chainparams);
SetThreadPriority (THREAD_PRIORITY_LOWEST);
Expand Down
Binary file modified src/qt/res/icons/bitcoin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen
IncrementExtraNonce(pblock, chainActive.Tip(), nExtraNonce);
}
while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount &&
!CheckProofOfWork(IsYesPower() ? pblock->GetHashYespower() : pblock->GetHashArgon2d(), pblock->nBits, Params().GetConsensus()))
!CheckProofOfWork(IsYesPower(nHeight) ? pblock->GetHashYespower() : pblock->GetHashArgon2d(), pblock->nBits, Params().GetConsensus()))
{
++pblock->nNonce;
--nMaxTries;
Expand Down
26 changes: 18 additions & 8 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,11 +1022,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus:
return error("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString());
}

if (IsYesPower()) LogPrintf("YesPower block\n"); else LogPrintf("Argon2d block\n");

// Check the header
if (!CheckProofOfWork(IsYesPower() ? block.GetHashYespower() : block.GetHashArgon2d(), block.nBits, consensusParams))
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
// this gets checked elsewhere anyway

return true;
}
Expand Down Expand Up @@ -2823,8 +2819,22 @@ static bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos,

static bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true)
{
// Get prev block index
CBlockIndex* pindexPrev = NULL;
int nHeight = 0;
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
if (mi != mapBlockIndex.end()) {
pindexPrev = mi->second;
nHeight = pindexPrev->nHeight + 1;
}

// Skip headers validation until we're close to chaintip
if (Params().NetworkIDString() == CBaseChainParams::MAIN)
if (nHeight < SKIP_BLOCKHEADER_POW)
return true;

// Check proof of work matches claimed amount
if (fCheckPOW && !CheckProofOfWork(IsYesPower() ? block.GetHashYespower() : block.GetHashArgon2d(), block.nBits, consensusParams))
if (fCheckPOW && !CheckProofOfWork(IsYesPower(nHeight) ? block.GetHashYespower() : block.GetHashArgon2d(), block.nBits, consensusParams))
return state.DoS(50, false, REJECT_INVALID, "high-hash", false, "proof of work failed");

return true;
Expand Down Expand Up @@ -4477,9 +4487,9 @@ double GuessVerificationProgress(const ChainTxData& data, CBlockIndex *pindex) {
return pindex->nChainTx / fTxTotal;
}

bool IsYesPower()
bool IsYesPower(int nHeight)
{
return (chainActive.Height() >= nYesPowerFork || gArgs.GetBoolArg("-testnet", false));
return (nHeight >= nYesPowerFork || gArgs.GetBoolArg("-testnet", false));
}

class CMainCleanup
Expand Down
8 changes: 5 additions & 3 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
/** The pre-allocation chunk size for rev?????.dat files (since 0.8) */
static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB

/** Skip PoW testing headers until this blockheight */
static const int SKIP_BLOCKHEADER_POW = 105000;
/** Maximum number of script-checking threads allowed */
static const int MAX_SCRIPTCHECK_THREADS = 16;
/** -par default (number of script-checking threads, 0 = auto) */
static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
/** Number of blocks that can be requested at any given time from a single peer. */
static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 256;
/** Timeout in seconds during which a peer must stall block download progress before being disconnected. */
static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
static const unsigned int BLOCK_STALLING_TIMEOUT = 4;
/** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends
* less than this number, we reached its tip. Changing this value is a protocol upgrade. */
static const unsigned int MAX_HEADERS_RESULTS = 2000;
Expand Down Expand Up @@ -488,6 +490,6 @@ void DumpMempool();
/** Load the mempool from disk. */
bool LoadMempool();

bool IsYesPower();
bool IsYesPower(int nHeight);

#endif // BITCOIN_VALIDATION_H

0 comments on commit 618bcd4

Please sign in to comment.