Trying to fix the forking issue, which is now clearly a bug in sending and receiving headers. This checkin will enable debugging and may be a fix.

This commit is contained in:
Michael Toutonghi
2018-05-15 22:19:07 -07:00
parent 32430433f3
commit 3da69a3138
3 changed files with 45 additions and 39 deletions

View File

@@ -3999,7 +3999,6 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
{ {
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1; const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1;
const Consensus::Params& consensusParams = Params().GetConsensus(); const Consensus::Params& consensusParams = Params().GetConsensus();
bool checkBlockOne = (nHeight == 1);
// Check that all transactions are finalized // Check that all transactions are finalized
BOOST_FOREACH(const CTransaction& tx, block.vtx) { BOOST_FOREACH(const CTransaction& tx, block.vtx) {
@@ -4087,7 +4086,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat
komodo_requestedhash = block.hashPrevBlock; komodo_requestedhash = block.hashPrevBlock;
komodo_requestedcount = 0; komodo_requestedcount = 0;
}*/ }*/
LogPrintf("AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str()); LogPrintf("AcceptBlockHeader %s\n hashPrevBlock %s not found\n", hash.ToString().c_str(), block.hashPrevBlock.ToString().c_str());
return(false); return(false);
//return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk");
} }
@@ -6016,8 +6015,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
pindex = chainActive.Next(pindex); pindex = chainActive.Next(pindex);
} }
// we must use CBlocks, as CBlockHeaders won't include the 0x00 nTx count at the end // we should probably use CBlocks, as CBlockHeaders won't include the 0x00 nTx count at the end
vector<CBlock> vHeaders; vector<CBlockHeader> vHeaders;
int nLimit = MAX_HEADERS_RESULTS; int nLimit = MAX_HEADERS_RESULTS;
LogPrint("net", "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), pfrom->id); LogPrint("net", "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), pfrom->id);
//if ( pfrom->lasthdrsreq >= chainActive.Height()-MAX_HEADERS_RESULTS || pfrom->lasthdrsreq != (int32_t)(pindex ? pindex->nHeight : -1) )// no need to ever suppress this //if ( pfrom->lasthdrsreq >= chainActive.Height()-MAX_HEADERS_RESULTS || pfrom->lasthdrsreq != (int32_t)(pindex ? pindex->nHeight : -1) )// no need to ever suppress this

View File

@@ -546,6 +546,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, bool isStake)
// Fill in header // Fill in header
pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashPrevBlock = pindexPrev->GetBlockHash();
pblock->hashReserved = uint256(); pblock->hashReserved = uint256();
if ( ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 ) if ( ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 )
{ {
UpdateTime(pblock, Params().GetConsensus(), pindexPrev); UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
@@ -777,16 +778,22 @@ int32_t waitForPeers(const CChainParams &chainparams)
{ {
if (chainparams.MiningRequiresPeers()) if (chainparams.MiningRequiresPeers())
{ {
do { bool fvNodesEmpty;
bool fvNodesEmpty; {
{ LOCK(cs_vNodes);
LOCK(cs_vNodes); fvNodesEmpty = vNodes.empty();
fvNodesEmpty = vNodes.empty(); }
} if (fvNodesEmpty)
if (!fvNodesEmpty ) {
break; do {
MilliSleep(1000 + rand() % 1900); MilliSleep(5000 + rand() % 5000);
} while (true); {
LOCK(cs_vNodes);
fvNodesEmpty = vNodes.empty();
}
} while (fvNodesEmpty);
MilliSleep(5000 + rand() % 5000);
}
} }
} }
@@ -817,18 +824,17 @@ void static VerusStaker(CWallet *pwallet)
break; break;
} }
SetThreadPriority(THREAD_PRIORITY_LOWEST);
// try a nice clean peer connection to start // try a nice clean peer connection to start
waitForPeers(chainparams); waitForPeers(chainparams);
sleep(5); // try a nice clean peer connection to start
CBlockIndex *curTip = chainActive.Tip(), *lastTip; waitForPeers(chainparams);
CBlockIndex* pindexPrev;
do { do {
lastTip = curTip; pindexPrev = chainActive.Tip();
printf("Verifying block height %d \n", lastTip->nHeight); MilliSleep(5000 + rand() % 5000);
MilliSleep(3000 + rand() % 1900); } while (pindexPrev != chainActive.Tip());
curTip = chainActive.Tip();
} while (curTip != lastTip);
SetThreadPriority(THREAD_PRIORITY_LOWEST);
sleep(5); sleep(5);
printf("Staking height %d for %s\n", chainActive.Tip()->nHeight + 1, ASSETCHAINS_SYMBOL); printf("Staking height %d for %s\n", chainActive.Tip()->nHeight + 1, ASSETCHAINS_SYMBOL);
@@ -940,11 +946,12 @@ void static VerusStaker(CWallet *pwallet)
ProcessBlockFound(pblock, *pwallet, reservekey); ProcessBlockFound(pblock, *pwallet, reservekey);
sleep(3);
// Check for stop or if block needs to be rebuilt // Check for stop or if block needs to be rebuilt
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
SetThreadPriority(THREAD_PRIORITY_LOWEST); SetThreadPriority(THREAD_PRIORITY_LOWEST);
sleep(5);
// In regression test mode, stop mining after a block is found. // In regression test mode, stop mining after a block is found.
if (chainparams.MineBlocksOnDemand()) { if (chainparams.MineBlocksOnDemand()) {
throw boost::thread_interrupted(); throw boost::thread_interrupted();
@@ -993,18 +1000,15 @@ void static BitcoinMiner_noeq()
break; break;
} }
SetThreadPriority(THREAD_PRIORITY_LOWEST);
// try a nice clean peer connection to start // try a nice clean peer connection to start
waitForPeers(chainparams); waitForPeers(chainparams);
MilliSleep(5000 + rand() % 5000); CBlockIndex* pindexPrev;
CBlockIndex *curTip = chainActive.Tip(), *lastTip;
do { do {
lastTip = curTip; pindexPrev = chainActive.Tip();
printf("Verifying block height %d \n", lastTip->nHeight); MilliSleep(5000 + rand() % 5000);
MilliSleep(1000 + rand() % 5000); } while (pindexPrev != chainActive.Tip());
curTip = chainActive.Tip();
} while (curTip != lastTip);
SetThreadPriority(THREAD_PRIORITY_LOWEST);
printf("Mining height %d\n", chainActive.Tip()->nHeight + 1); printf("Mining height %d\n", chainActive.Tip()->nHeight + 1);
@@ -1017,16 +1021,16 @@ void static BitcoinMiner_noeq()
miningTimer.stop(); miningTimer.stop();
waitForPeers(chainparams); waitForPeers(chainparams);
CBlockIndex* pindexPrev = chainActive.Tip(); pindexPrev = chainActive.Tip();
sleep(1);
// prevent forking on startup before the diff algorithm kicks in // prevent forking on startup before the diff algorithm kicks in
if (pindexPrev->nHeight < 70) if (pindexPrev->nHeight < 50 || pindexPrev != chainActive.Tip())
{ {
do { do {
lastTip = pindexPrev;
MilliSleep(3000 + rand() % 5000);
pindexPrev = chainActive.Tip(); pindexPrev = chainActive.Tip();
} while (pindexPrev != lastTip); MilliSleep(5000 + rand() % 5000);
} while (pindexPrev != chainActive.Tip());
} }
miningTimer.start(); miningTimer.start();

View File

@@ -76,7 +76,10 @@ public:
uint256 GetHash() const uint256 GetHash() const
{ {
return (this->*hashFunction)(); if (hashPrevBlock.IsNull())
return (this->GetSHA256DHash());
else
return (this->*hashFunction)();
} }
uint256 GetSHA256DHash() const; uint256 GetSHA256DHash() const;