Remove spurios opret in tx builder, don't wait forever for blocks before mining, add delay to getblocktemplate

This commit is contained in:
miketout
2018-10-11 21:35:09 -07:00
parent 271326fafd
commit af2e212d7a
5 changed files with 77 additions and 16 deletions

View File

@@ -1566,7 +1566,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
string reason; string reason;
if (Params().RequireStandard() && !IsStandardTx(tx, reason, nextBlockHeight)) if (Params().RequireStandard() && !IsStandardTx(tx, reason, nextBlockHeight))
{ {
//fprintf(stderr,"AcceptToMemoryPool reject nonstandard transaction: %s\n",reason.c_str()); //
//fprintf(stderr,"AcceptToMemoryPool reject nonstandard transaction: %s\nscriptPubKey: %s\n",reason.c_str(),tx.vout[0].scriptPubKey.ToString().c_str());
return state.DoS(0,error("AcceptToMemoryPool: nonstandard transaction: %s", reason),REJECT_NONSTANDARD, reason); return state.DoS(0,error("AcceptToMemoryPool: nonstandard transaction: %s", reason),REJECT_NONSTANDARD, reason);
} }
// Only accept nLockTime-using transactions that can be mined in the next // Only accept nLockTime-using transactions that can be mined in the next
@@ -2186,22 +2187,22 @@ bool IsInitialBlockDownload()
} }
// determine if we are in sync with the best chain // determine if we are in sync with the best chain
bool IsInSync() int IsNotInSync()
{ {
const CChainParams& chainParams = Params(); const CChainParams& chainParams = Params();
LOCK(cs_main); LOCK(cs_main);
if (fImporting || fReindex) if (fImporting || fReindex)
{ {
//fprintf(stderr,"IsInSync: fImporting %d || %d fReindex\n",(int32_t)fImporting,(int32_t)fReindex); //fprintf(stderr,"IsNotInSync: fImporting %d || %d fReindex\n",(int32_t)fImporting,(int32_t)fReindex);
return false; return true;
} }
if (fCheckpointsEnabled) if (fCheckpointsEnabled)
{ {
if (fCheckpointsEnabled && chainActive.Height() < Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints())) if (fCheckpointsEnabled && chainActive.Height() < Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints()))
{ {
//fprintf(stderr,"IsInSync: checkpoint -> initialdownload chainActive.Height().%d GetTotalBlocksEstimate(chainParams.Checkpoints().%d\n", chainActive.Height(), Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints())); //fprintf(stderr,"IsNotInSync: checkpoint -> initialdownload chainActive.Height().%d GetTotalBlocksEstimate(chainParams.Checkpoints().%d\n", chainActive.Height(), Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints()));
return false; return true;
} }
} }
@@ -2211,9 +2212,13 @@ bool IsInSync()
(pindexBestHeader == 0) || (pindexBestHeader == 0) ||
((pindexBestHeader->GetHeight() - 1) > pbi->GetHeight()) || ((pindexBestHeader->GetHeight() - 1) > pbi->GetHeight()) ||
(longestchain != 0 && longestchain > pbi->GetHeight()) ) (longestchain != 0 && longestchain > pbi->GetHeight()) )
return false; {
return (pbi && pindexBestHeader && (pindexBestHeader->GetHeight() - 1) > pbi->GetHeight()) ?
pindexBestHeader->GetHeight() - pbi->GetHeight() :
true;
}
return true; return false;
} }
static bool fLargeWorkForkFound = false; static bool fLargeWorkForkFound = false;

View File

@@ -228,8 +228,10 @@ void ThreadScriptCheck();
void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const CBlockIndex *const &bestHeader, int64_t nPowTargetSpacing); void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const CBlockIndex *const &bestHeader, int64_t nPowTargetSpacing);
/** Check whether we are doing an initial block download (synchronizing from disk or network) */ /** Check whether we are doing an initial block download (synchronizing from disk or network) */
bool IsInitialBlockDownload(); bool IsInitialBlockDownload();
/** Check if the daemon is in sync */ /** Check if the daemon is in sync, if not, it returns 1 or if due to best header only, the difference in best
bool IsInSync(); * header and activeChain tip
*/
int IsNotInSync();
/** Format a string that describes several potential problems detected by the core */ /** Format a string that describes several potential problems detected by the core */
std::string GetWarnings(const std::string& strFor); std::string GetWarnings(const std::string& strFor);
/** Retrieve a transaction (from memory pool, or from disk, if possible) */ /** Retrieve a transaction (from memory pool, or from disk, if possible) */

View File

@@ -923,8 +923,10 @@ int32_t waitForPeers(const CChainParams &chainparams)
LOCK(cs_vNodes); LOCK(cs_vNodes);
fvNodesEmpty = vNodes.empty(); fvNodesEmpty = vNodes.empty();
} }
if (fvNodesEmpty || !IsInSync()) if (fvNodesEmpty || IsNotInSync())
{ {
int loops = 0, blockDiff = 0, newDiff = 0;
do { do {
if (fvNodesEmpty) if (fvNodesEmpty)
MilliSleep(1000 + rand() % 4000); MilliSleep(1000 + rand() % 4000);
@@ -932,8 +934,25 @@ int32_t waitForPeers(const CChainParams &chainparams)
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
LOCK(cs_vNodes); LOCK(cs_vNodes);
fvNodesEmpty = vNodes.empty(); fvNodesEmpty = vNodes.empty();
loops = 0;
blockDiff = 0;
} }
} while (fvNodesEmpty || !IsInSync()); if ((newDiff = IsNotInSync()) > 1)
{
if (blockDiff != newDiff)
{
blockDiff = newDiff;
}
else
{
if (++loops <= 90)
{
MilliSleep(1000);
}
else break;
}
}
} while (fvNodesEmpty || IsNotInSync());
MilliSleep(100 + rand() % 400); MilliSleep(100 + rand() % 400);
} }
} }

View File

@@ -604,8 +604,43 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
if (strMode != "template") if (strMode != "template")
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
if (Params().MiningRequiresPeers() && (!IsInSync() || vNodes.empty())) bool fvNodesEmpty;
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Cannot get a block template while no peers are connected or chain not in sync!"); {
LOCK(cs_vNodes);
fvNodesEmpty = vNodes.empty();
}
if (Params().MiningRequiresPeers() && (IsNotInSync() || fvNodesEmpty))
{
int loops = 0, blockDiff = 0, newDiff = 0;
do {
if (fvNodesEmpty)
MilliSleep(1000 + rand() % 4000);
{
LOCK(cs_vNodes);
fvNodesEmpty = vNodes.empty();
loops = 0;
blockDiff = 0;
}
if ((newDiff = IsNotInSync()) > 1)
{
if (blockDiff != newDiff)
{
blockDiff = newDiff;
}
else
{
if (++loops <= 30)
{
MilliSleep(1000);
}
else break;
}
}
} while (fvNodesEmpty || IsNotInSync());
if (loops > 30)
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Cannot get a block template while no peers are connected or chain not in sync!");
}
//if (IsInitialBlockDownload()) //if (IsInitialBlockDownload())
// throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Zcash is downloading blocks..."); // throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Zcash is downloading blocks...");

View File

@@ -85,9 +85,9 @@ bool TransactionBuilder::AddOpRetLast()
if (opReturn) if (opReturn)
{ {
s = opReturn.value(); s = opReturn.value();
CTxOut out(0, s);
mtx.vout.push_back(out);
} }
CTxOut out(0, s);
mtx.vout.push_back(out);
return true; return true;
} }