From 5cb458b5f20cdeda85d774dd93cac43850007fb5 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 10 Jan 2019 16:44:09 +0800 Subject: [PATCH] fix bug with getimports... Fix miner loop deadlock with staker. Remove annoying pointless prints for staker. --- src/komodo_bitcoind.h | 4 ++-- src/miner.cpp | 16 +++++++++------- src/rpc/crosschain.cpp | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fda088631..260f6bc14 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2106,7 +2106,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt counter++; if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) { - fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); + //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); continue; } CAmount nValue = out.tx->vout[out.i].nValue; @@ -2160,7 +2160,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else { - fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); + //fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); continue; } eligible = besttime; diff --git a/src/miner.cpp b/src/miner.cpp index 957d4cbba..714641bc0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -494,12 +494,14 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); //pblock->nTime = blocktime + 1; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); - + int32_t stakeHeight = chainActive.Height() + 1; //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); if ( ASSETCHAINS_SYMBOL[0] != 0 && isStake ) { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), stakeHeight); @@ -520,11 +522,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, blocktime = GetAdjustedTime(); //if ( blocktime > pindexPrev->GetMedianTimePast()+60 ) // blocktime = pindexPrev->GetMedianTimePast() + 60; - LEAVE_CRITICAL_SECTION(cs_main); - LEAVE_CRITICAL_SECTION(mempool.cs); siglen = komodo_staked(txStaked, pblock->nBits, &blocktime, &txtime, &utxotxid, &utxovout, &utxovalue, utxosig); - ENTER_CRITICAL_SECTION(cs_main); - ENTER_CRITICAL_SECTION(mempool.cs); } if ( siglen > 0 ) @@ -540,6 +538,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, pblock->nTime = blocktime; //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); + } // Create coinbase tx CMutableTransaction txNew = CreateNewContextualCMutableTransaction(consensusParams, nHeight); @@ -678,8 +677,11 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, //fprintf(stderr,"valid\n"); } } - LEAVE_CRITICAL_SECTION(cs_main); - LEAVE_CRITICAL_SECTION(mempool.cs); + if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) + { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); + } //fprintf(stderr,"done new block\n"); return pblocktemplate.release(); } diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 15e27ead2..e2770b28c 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -363,7 +363,7 @@ UniValue getimports(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "getmigrates \"hash|height\"\n" + "getimports \"hash|height\"\n" "\n\n" "\nResult:\n" "{\n" @@ -429,7 +429,7 @@ UniValue getimports(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); UniValue result(UniValue::VOBJ); - CAmount TotalImported; + CAmount TotalImported = 0; UniValue imports(UniValue::VARR); BOOST_FOREACH(const CTransaction&tx, block.vtx) { @@ -467,7 +467,7 @@ UniValue getimports(const UniValue& params, bool fHelp) } } result.push_back(Pair("imports", imports)); - result.push_back(Pair("TotalImported", ValueFromAmount(TotalImported))); + result.push_back(Pair("TotalImported", TotalImported > 0 ? ValueFromAmount(TotalImported) : 0 )); result.push_back(Pair("time", block.GetBlockTime())); return result; }