From 777ee028126482e773dfefc20b80038244dd1d90 Mon Sep 17 00:00:00 2001 From: John Jones Date: Fri, 27 Aug 2021 17:14:11 -0500 Subject: [PATCH 1/3] lock cs_main for TestBlockValidity --- src/main.cpp | 4 --- src/miner.cpp | 70 ++++++++++++++++++++------------------------------- 2 files changed, 27 insertions(+), 47 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b61d7bb79c7..ee4aa6107c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5846,23 +5846,19 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex // NOTE: CheckBlockHeader is called by CheckBlock if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { - //fprintf(stderr,"TestBlockValidity failure A checkPOW.%d\n",fCheckPOW); return false; } int32_t futureblock; if (!CheckBlock(&futureblock,indexDummy.GetHeight(),0,block, state, verifier, fCheckPOW, fCheckMerkleRoot)) { - //fprintf(stderr,"TestBlockValidity failure B checkPOW.%d\n",fCheckPOW); return false; } if (!ContextualCheckBlock(0,block, state, pindexPrev)) { - //fprintf(stderr,"TestBlockValidity failure C checkPOW.%d\n",fCheckPOW); return false; } if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW)) { - //fprintf(stderr,"TestBlockValidity failure D checkPOW.%d\n",fCheckPOW); return false; } assert(state.IsValid()); diff --git a/src/miner.cpp b/src/miner.cpp index c8bd108f63e..c88ff47fbad 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1699,6 +1699,12 @@ void static BitcoinMiner_noeq() int32_t gotinvalid; extern int32_t getkmdseason(int32_t height); +CBlockIndex * GetLastTipWithLock() +{ + LOCK(cs_main); + return chainActive.LastTip(); +} + #ifdef ENABLE_WALLET void static BitcoinMiner(CWallet *pwallet) #else @@ -1728,7 +1734,16 @@ void static BitcoinMiner() break; } if ( ASSETCHAINS_SYMBOL[0] == 0 ) - komodo_chosennotary(¬aryid,chainActive.Height()+1,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetMedianTimePast()); + { + int newHeight; + uint32_t timePast; + { + LOCK(cs_main); + newHeight = chainActive.Height() + 1; + timePast = (uint32_t)chainActive.Tip()->GetMedianTimePast(); + } + komodo_chosennotary(¬aryid,newHeight,NOTARY_PUBKEY33,timePast); + } if ( notaryid != My_notaryid ) My_notaryid = notaryid; std::string solver; @@ -1755,10 +1770,8 @@ void static BitcoinMiner() fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str()); while (true) { - if (chainparams.MiningRequiresPeers()) //chainActive.LastTip()->GetHeight() != 235300 && + if (chainparams.MiningRequiresPeers()) { - //if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->GetHeight() < 100 ) - // break; // Busy-wait for the network to come online so we don't waste time mining // on an obsolete chain. In regtest mode we expect to fly solo. miningTimer.stop(); @@ -1781,17 +1794,12 @@ void static BitcoinMiner() // Create new block // unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); - CBlockIndex* pindexPrev = chainActive.LastTip(); + CBlockIndex* pindexPrev = GetLastTipWithLock(); if ( Mining_height != pindexPrev->GetHeight()+1 ) { Mining_height = pindexPrev->GetHeight()+1; Mining_start = (uint32_t)time(NULL); } - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED == 0 ) - { - //fprintf(stderr,"%s create new block ht.%d\n",ASSETCHAINS_SYMBOL,Mining_height); - //sleep(3); - } #ifdef ENABLE_WALLET // notaries always default to staking @@ -1966,28 +1974,16 @@ void static BitcoinMiner() solutionTargetChecks.increment(); B = *pblock; h = UintToArith256(B.GetHash()); - /*for (z=31; z>=16; z--) - fprintf(stderr,"%02x",((uint8_t *)&h)[z]); - fprintf(stderr," mined "); - for (z=31; z>=16; z--) - fprintf(stderr,"%02x",((uint8_t *)&HASHTarget)[z]); - fprintf(stderr," hashTarget "); - for (z=31; z>=16; z--) - fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," POW\n");*/ if ( h > hashTarget ) { - //if ( ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0 ) - // MilliSleep(30); return false; } if ( IS_KOMODO_NOTARY && B.nTime > GetTime() ) { - //fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); while ( GetTime() < B.nTime-2 ) { sleep(1); - if ( chainActive.LastTip()->GetHeight() >= Mining_height ) + if ( GetLastTipWithLock()->GetHeight() >= Mining_height ) { fprintf(stderr,"new block arrived\n"); return(false); @@ -2022,13 +2018,15 @@ void static BitcoinMiner() fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); fprintf(stderr, "\n"); } - CValidationState state; - if ( !TestBlockValidity(state,B, chainActive.LastTip(), true, false)) + bool blockValid; + { + LOCK(cs_main); + CValidationState state; + blockValid = TestBlockValidity(state, B, chainActive.LastTip(), true, false); + } + if ( !blockValid ) { h = UintToArith256(B.GetHash()); - //for (z=31; z>=0; z--) - // fprintf(stderr,"%02x",((uint8_t *)&h)[z]); - //fprintf(stderr," Invalid block mined, try again\n"); gotinvalid = 1; return(false); } @@ -2143,10 +2141,8 @@ void static BitcoinMiner() fprintf(stderr,"timeout, break\n"); break; } - if ( pindexPrev != chainActive.LastTip() ) + if ( pindexPrev != GetLastTipWithLock() ) { - if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) - fprintf(stderr,"Tip advanced, break\n"); break; } // Update nNonce and nTime @@ -2158,19 +2154,7 @@ void static BitcoinMiner() HASHTarget.SetCompact(pblock->nBits); hashTarget = HASHTarget; savebits = pblock->nBits; - //hashTarget = HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); } - /*if ( NOTARY_PUBKEY33[0] == 0 ) - { - int32_t percPoS; - UpdateTime(pblock, consensusParams, pindexPrev); - if (consensusParams.fPowAllowMinDifficultyBlocks) - { - // Changing pblock->nTime can change work required on testnet: - HASHTarget.SetCompact(pblock->nBits); - HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - } - }*/ } } } From e2cf441955b855b412816a507a37f15b87782ff7 Mon Sep 17 00:00:00 2001 From: John Jones Date: Fri, 24 Sep 2021 16:19:23 -0500 Subject: [PATCH 2/3] Remove LastTip() --- src/cc/CCutils.cpp | 6 +- src/cc/marmara.cpp | 10 ++-- src/cc/payments.cpp | 2 +- src/cc/rewards.cpp | 2 +- src/cc/sudoku.cpp | 4 +- src/chain.h | 9 +-- src/komodo.cpp | 4 +- src/komodo_bitcoind.cpp | 22 +++---- src/komodo_gateway.cpp | 2 +- src/komodo_jumblr.cpp | 2 +- src/komodo_nSPV_fullnode.h | 12 ++-- src/komodo_nSPV_wallet.h | 2 +- src/komodo_pax.cpp | 4 +- src/main.cpp | 72 +++++++++++------------ src/metrics.cpp | 2 +- src/miner.cpp | 72 +++++++++++------------ src/rest.cpp | 6 +- src/rpc/blockchain.cpp | 32 +++++----- src/rpc/mining.cpp | 26 ++++---- src/rpc/misc.cpp | 12 ++-- src/rpc/rawtransaction.cpp | 4 +- src/txmempool.cpp | 2 +- src/wallet/asyncrpcoperation_sendmany.cpp | 20 +++---- src/wallet/rpcdump.cpp | 4 +- src/wallet/rpcwallet.cpp | 24 ++++---- src/wallet/wallet.cpp | 18 +++--- 26 files changed, 185 insertions(+), 190 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index bd79eaa6857..a52fca5a1b4 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -534,7 +534,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) fprintf(stderr,"CCduration no txtime %u or txheight.%d %p for txid %s\n",txtime,txheight,pindex,uint256_str(str,txid)); return(0); } - else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->GetHeight() <= txheight ) + else if ( (pindex= chainActive.Tip()) == 0 || pindex->nTime < txtime || pindex->GetHeight() <= txheight ) { if ( pindex->nTime < txtime ) fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->GetHeight()); @@ -672,7 +672,7 @@ int32_t komodo_get_current_height() { return (NSPV_inforesult.height); } - else return chainActive.LastTip()->GetHeight(); + else return chainActive.Tip()->GetHeight(); } bool komodo_txnotarizedconfirmed(uint256 txid) @@ -720,7 +720,7 @@ bool komodo_txnotarizedconfirmed(uint256 txid) fprintf(stderr,"komodo_txnotarizedconfirmed no txheight.%d %p for txid %s\n",txheight,pindex,txid.ToString().c_str()); return(0); } - else if ( (pindex= chainActive.LastTip()) == 0 || pindex->GetHeight() < txheight ) + else if ( (pindex= chainActive.Tip()) == 0 || pindex->GetHeight() < txheight ) { fprintf(stderr,"komodo_txnotarizedconfirmed backwards heights for txid %s hts.(%d %d)\n",txid.ToString().c_str(),txheight,(int32_t)pindex->GetHeight()); return(0); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 91c458eaec6..5d0f8b63338 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -551,7 +551,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); remaining = change = 0; - height = chainActive.LastTip()->GetHeight(); + height = chainActive.Tip()->GetHeight(); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 ) { if ( myGetTransaction(batontxid,batontx,hashBlock) != 0 && (numvouts= batontx.vout.size()) > 1 ) @@ -564,9 +564,9 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) result.push_back(Pair("error",(char *)"invalid refcreatetxid, setting to creditloop[0]")); return(result); } - else if ( chainActive.LastTip()->GetHeight() < refmatures ) + else if ( chainActive.Tip()->GetHeight() < refmatures ) { - fprintf(stderr,"doesnt mature for another %d blocks\n",refmatures - chainActive.LastTip()->GetHeight()); + fprintf(stderr,"doesnt mature for another %d blocks\n",refmatures - chainActive.Tip()->GetHeight()); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"cant settle immature creditloop")); return(result); @@ -713,7 +713,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri errorstr = (char *)"for now, only MARMARA loops are supported"; else if ( amount <= txfee ) errorstr = (char *)"amount must be for more than txfee"; - else if ( matures <= chainActive.LastTip()->GetHeight() ) + else if ( matures <= chainActive.Tip()->GetHeight() ) errorstr = (char *)"it must mature in the future"; if ( errorstr == 0 ) { @@ -767,7 +767,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a errorstr = (char *)"for now, only MARMARA loops are supported"; else if ( amount <= txfee ) errorstr = (char *)"amount must be for more than txfee"; - else if ( matures <= chainActive.LastTip()->GetHeight() ) + else if ( matures <= chainActive.Tip()->GetHeight() ) errorstr = (char *)"it must mature in the future"; if ( errorstr == 0 ) { diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 048ade82adb..96726343b67 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -351,7 +351,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & txidpk = CCtxidaddr(txidaddr,createtxid); GetCCaddress1of2(cp,txidaddr,Paymentspk,txidpk); //fprintf(stderr, "lockedblocks.%i minrelease.%i totalallocations.%i txidopret1.%s txidopret2.%s\n",lockedblocks, minrelease, totalallocations, txidoprets[0].ToString().c_str(), txidoprets[1].ToString().c_str() ); - if ( !CheckTxFee(tx, PAYMENTS_TXFEE+1, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime, actualtxfee) ) + if ( !CheckTxFee(tx, PAYMENTS_TXFEE+1, chainActive.Tip()->GetHeight(), chainActive.Tip()->nTime, actualtxfee) ) return eval->Invalid("txfee is too high"); // Check that the change vout is playing the txid address. if ( IsPaymentsvout(cp,tx,0,txidaddr,ccopret) == 0 ) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index df1ab6871b7..33d7f5d5bb9 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -294,7 +294,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t if ( (*cp->ismyvin)(tx.vin[i].scriptSig) == 0 ) return eval->Invalid("unexpected normal vin for unlock"); } - if ( !CheckTxFee(tx, txfee, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime, dummy) ) + if ( !CheckTxFee(tx, txfee, chainActive.Tip()->GetHeight(), chainActive.Tip()->nTime, dummy) ) return eval->Invalid("txfee is too high"); amount = vinTx.vout[0].nValue; reward = RewardsCalc((int64_t)amount,tx.vin[0].prevout.hash,(int64_t)APR,(int64_t)minseconds,(int64_t)maxseconds,GetLatestTimestamp(eval->GetCurrentHeight())); diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 8017799ba72..c8d05025213 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2537,7 +2537,7 @@ int32_t sudoku_captcha(int32_t dispflag,uint32_t timestamps[81],int32_t height) printf("list[0] %u vs list[%d-1] %u\n",list[0],n,list[n-1]); retval = -1; } - else if ( list[n-1] > chainActive.LastTip()->nTime+200 ) + else if ( list[n-1] > chainActive.Tip()->nTime+200 ) retval = -2; else if ( solvetime >= 777 ) retval = 0; @@ -2658,7 +2658,7 @@ UniValue sudoku_generate(uint64_t txfee,struct CCcontract_info *cp,cJSON *params result.push_back(Pair("result","success")); result.push_back(Pair("name","sudoku")); result.push_back(Pair("method","gen")); - hash = chainActive.LastTip()->GetBlockHash(); + hash = chainActive.Tip()->GetBlockHash(); memcpy(&srandi,&hash,sizeof(srandi)); srandi ^= (uint32_t)time(NULL); while ( 1 ) diff --git a/src/chain.h b/src/chain.h index b1d9dee451b..e3c5e0b45dd 100644 --- a/src/chain.h +++ b/src/chain.h @@ -606,16 +606,11 @@ class CChain { return vChain.size() > 0 ? vChain[0] : NULL; } - /** Returns the index entry for the tip of this chain, or NULL if none. */ + /** Returns the index entry for the tip of this chain, or nullptr if none. */ CBlockIndex *Tip() const { - return vChain.size() > 0 ? vChain[vChain.size() - 1] : NULL; + return vChain.size() > 0 ? vChain[vChain.size() - 1] : nullptr; } - /** Returns the last tip of the chain, or NULL if none. */ - CBlockIndex *LastTip() const { - return vChain.size() > 0 ? lastTip : NULL; - } - /** Returns the index entry at a particular height in this chain, or NULL if no such height exists. */ CBlockIndex *operator[](int nHeight) const { if (nHeight < 0 || nHeight >= (int)vChain.size()) diff --git a/src/komodo.cpp b/src/komodo.cpp index fb9b2e864de..db529b228a1 100644 --- a/src/komodo.cpp +++ b/src/komodo.cpp @@ -653,7 +653,7 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) komodo_stateupdate(pindex->GetHeight(),0,0,0,zero,0,0,0,0,-pindex->GetHeight(),pindex->nTime,0,0,0,0,zero,0); } } - komodo_currentheight_set(chainActive.LastTip()->GetHeight()); + komodo_currentheight_set(chainActive.Tip()->GetHeight()); int transaction = 0; if ( pindex != 0 ) { @@ -732,7 +732,7 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) ) { memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); - notaryid = komodo_voutupdate(fJustCheck,&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime()); + notaryid = komodo_voutupdate(fJustCheck,&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.Tip()->GetBlockTime()); if ( fJustCheck && notaryid == -2 ) { // We see a valid notarisation here, save its location. diff --git a/src/komodo_bitcoind.cpp b/src/komodo_bitcoind.cpp index d74a5064b21..b01efe97241 100644 --- a/src/komodo_bitcoind.cpp +++ b/src/komodo_bitcoind.cpp @@ -819,20 +819,20 @@ int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex) uint32_t komodo_chainactive_timestamp() { - if ( chainActive.LastTip() != 0 ) - return((uint32_t)chainActive.LastTip()->GetBlockTime()); + if ( chainActive.Tip() != 0 ) + return((uint32_t)chainActive.Tip()->GetBlockTime()); else return(0); } CBlockIndex *komodo_chainactive(int32_t height) { - if ( chainActive.LastTip() != 0 ) + if ( chainActive.Tip() != 0 ) { - if ( height <= chainActive.LastTip()->GetHeight() ) + if ( height <= chainActive.Tip()->GetHeight() ) return(chainActive[height]); - // else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.LastTip()->GetHeight()); + // else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->GetHeight()); } - //fprintf(stderr,"komodo_chainactive null chainActive.LastTip() height %d\n",height); + //fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height); return(0); } @@ -1024,7 +1024,7 @@ uint32_t komodo_blocktime(uint256 hash) int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash) { int32_t notarized_height,MoMdepth; uint256 MoM,notarized_hash,notarized_desttxid; CBlockIndex *notary,*pindex; - if ( (pindex= chainActive.LastTip()) == 0 ) + if ( (pindex= chainActive.Tip()) == 0 ) return(-1); notarized_height = komodo_notarizeddata(pindex->GetHeight(),¬arized_hash,¬arized_desttxid); *notarized_heightp = notarized_height; @@ -1067,7 +1067,7 @@ uint32_t komodo_interest_args(uint32_t *txheighttimep,int32_t *txheightp,uint32_ *valuep = tx.vout[n].nValue; *txheightp = pindex->GetHeight(); *txheighttimep = pindex->nTime; - if ( *tiptimep == 0 && (tipindex= chainActive.LastTip()) != 0 ) + if ( *tiptimep == 0 && (tipindex= chainActive.Tip()) != 0 ) *tiptimep = (uint32_t)tipindex->nTime; locktime = tx.nLockTime; //fprintf(stderr,"tx locktime.%u %.8f height.%d | tiptime.%u\n",locktime,(double)*valuep/COIN,*txheightp,*tiptimep); @@ -1097,7 +1097,7 @@ uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 int32_t komodo_nextheight() { CBlockIndex *pindex; int32_t ht; - if ( (pindex= chainActive.LastTip()) != 0 && (ht= pindex->GetHeight()) > 0 ) + if ( (pindex= chainActive.Tip()) != 0 && (ht= pindex->GetHeight()) > 0 ) return(ht+1); else return(komodo_longestchain() + 1); } @@ -1108,7 +1108,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) if ( (sp= komodo_stateptrget((char *)"KMD")) != 0 ) *kmdheightp = sp->CURRENT_HEIGHT; else *kmdheightp = 0; - if ( (pindex= chainActive.LastTip()) != 0 && pindex->GetHeight() >= (int32_t)komodo_longestchain() ) + if ( (pindex= chainActive.Tip()) != 0 && pindex->GetHeight() >= (int32_t)komodo_longestchain() ) return(1); else return(0); } @@ -2354,7 +2354,7 @@ int32_t komodo_acpublic(uint32_t tiptime) { if ( tiptime == 0 ) { - if ( (pindex= chainActive.LastTip()) != 0 ) + if ( (pindex= chainActive.Tip()) != 0 ) tiptime = pindex->nTime; } if ( (ASSETCHAINS_SYMBOL[0] == 0 || strcmp(ASSETCHAINS_SYMBOL,"ZEX") == 0) && tiptime >= KOMODO_SAPLING_DEADLINE ) diff --git a/src/komodo_gateway.cpp b/src/komodo_gateway.cpp index d840df4574a..b53996008ef 100644 --- a/src/komodo_gateway.cpp +++ b/src/komodo_gateway.cpp @@ -1546,7 +1546,7 @@ void komodo_passport_iteration() komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"realtime"); if ( (fp= fopen(fname,"wb")) != 0 ) { - buf[0] = (uint32_t)chainActive.LastTip()->GetHeight(); + buf[0] = (uint32_t)chainActive.Tip()->GetHeight(); buf[1] = (uint32_t)komodo_longestchain(); if ( buf[0] != 0 && buf[0] == buf[1] ) { diff --git a/src/komodo_jumblr.cpp b/src/komodo_jumblr.cpp index f82d3152757..d02f9a2f459 100644 --- a/src/komodo_jumblr.cpp +++ b/src/komodo_jumblr.cpp @@ -620,7 +620,7 @@ void jumblr_iteration() free(retstr), retstr = 0; } } - height = (int32_t)chainActive.LastTip()->GetHeight(); + height = (int32_t)chainActive.Tip()->GetHeight(); if ( time(NULL) < lasttime+40 ) return; lasttime = (uint32_t)time(NULL); diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index ea6156a5b2c..a6a3001274b 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -90,7 +90,7 @@ int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t origreqheight) { struct NSPV_ntzargs prev,next; int32_t reqheight = origreqheight; - if ( reqheight < chainActive.LastTip()->GetHeight() ) + if ( reqheight < chainActive.Tip()->GetHeight() ) reqheight++; if ( NSPV_notarized_bracket(&prev,&next,reqheight) == 0 ) { @@ -132,7 +132,7 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) { int32_t prevMoMheight,len = 0; CBlockIndex *pindex, *pindex2; struct NSPV_ntzsresp pair; - if ( (pindex= chainActive.LastTip()) != 0 ) + if ( (pindex= chainActive.Tip()) != 0 ) { ptr->height = pindex->GetHeight(); ptr->blockhash = pindex->GetBlockHash(); @@ -167,7 +167,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC skipcount = 0; if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) >= 0 && ptr->numutxos < maxlen ) { - tipheight = chainActive.LastTip()->GetHeight(); + tipheight = chainActive.Tip()->GetHeight(); ptr->nodeheight = tipheight; if ( skipcount >= ptr->numutxos ) skipcount = ptr->numutxos-1; @@ -333,7 +333,7 @@ int32_t NSPV_getccmoduleutxos(struct NSPV_utxosresp *ptr, char *coinaddr, int64_ ptr->numutxos = 0; strncpy(ptr->coinaddr, coinaddr, sizeof(ptr->coinaddr) - 1); ptr->CCflag = 1; - tipheight = chainActive.LastTip()->GetHeight(); + tipheight = chainActive.Tip()->GetHeight(); ptr->nodeheight = tipheight; // will be checked in libnspv //} @@ -441,7 +441,7 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC int32_t maxlen,txheight,ind=0,n = 0,len = 0; CTransaction tx; uint256 hashBlock; std::vector > txids; SetCCtxids(txids,coinaddr,isCC); - ptr->nodeheight = chainActive.LastTip()->GetHeight(); + ptr->nodeheight = chainActive.Tip()->GetHeight(); maxlen = MAX_BLOCK_SIZE(ptr->nodeheight) - 512; maxlen /= sizeof(*ptr->txids); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); @@ -624,7 +624,7 @@ int32_t NSPV_mempoolfuncs(bits256 *satoshisp,int32_t *vindexp,std::vector txids; bits256 satoshis; uint256 tmp,tmpdest; int32_t i,len = 0; - ptr->nodeheight = chainActive.LastTip()->GetHeight(); + ptr->nodeheight = chainActive.Tip()->GetHeight(); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); ptr->CCflag = isCC; ptr->txid = txid; diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index f745629b747..bc4b62c8bd7 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -389,7 +389,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; mtx.nVersion = SAPLING_TX_VERSION; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - if ( !komodo_hardfork_active((uint32_t)chainActive.LastTip()->nTime) ) + if ( !komodo_hardfork_active((uint32_t)chainActive.Tip()->nTime) ) mtx.nLockTime = (uint32_t)time(NULL) - 777; else mtx.nLockTime = (uint32_t)chainActive.Tip()->GetMedianTimePast(); diff --git a/src/komodo_pax.cpp b/src/komodo_pax.cpp index d9cb8f7032f..e6385e92fde 100644 --- a/src/komodo_pax.cpp +++ b/src/komodo_pax.cpp @@ -593,13 +593,13 @@ uint64_t komodo_paxpriceB(uint64_t seed,int32_t height,char *base,char *rel,uint uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,nonz=0; int64_t diff; uint64_t price,seed,sum = 0; - if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && height > chainActive.LastTip()->GetHeight() ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && height > chainActive.Tip()->GetHeight() ) { if ( height < 100000000 ) { static uint32_t counter; if ( counter++ < 3 ) - printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.LastTip()->GetHeight()); + printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.Tip()->GetHeight()); } return(0); } diff --git a/src/main.cpp b/src/main.cpp index ab451a08c9a..267b7d97b15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -356,7 +356,7 @@ namespace { int GetHeight() { CBlockIndex *pindex; - if ( (pindex= chainActive.LastTip()) != 0 ) + if ( (pindex= chainActive.Tip()) != 0 ) return pindex->GetHeight(); else return(0); } @@ -1274,7 +1274,7 @@ bool ContextualCheckTransaction(int32_t slowflag,const CBlock *block, CBlockInde // Rules that apply before Sapling: if (!saplingActive) { // Size limits - //BOOST_STATIC_ASSERT(MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1) > MAX_TX_SIZE_BEFORE_SAPLING); // sanity + //BOOST_STATIC_ASSERT(MAX_BLOCK_SIZE(chainActive.Tip()->GetHeight()+1) > MAX_TX_SIZE_BEFORE_SAPLING); // sanity if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) > MAX_TX_SIZE_BEFORE_SAPLING) return state.DoS(100, error("ContextualCheckTransaction(): size limits failed"), REJECT_INVALID, "bad-txns-oversize"); @@ -1513,7 +1513,7 @@ bool CheckTransactionWithoutProofVerification(uint32_t tiptime,const CTransactio REJECT_INVALID, "bad-txns-vout-empty"); // Size limits - //BOOST_STATIC_ASSERT(MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1) >= MAX_TX_SIZE_AFTER_SAPLING); // sanity + //BOOST_STATIC_ASSERT(MAX_BLOCK_SIZE(chainActive.Tip()->GetHeight()+1) >= MAX_TX_SIZE_AFTER_SAPLING); // sanity BOOST_STATIC_ASSERT(MAX_TX_SIZE_AFTER_SAPLING > MAX_TX_SIZE_BEFORE_SAPLING); // sanity if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) > MAX_TX_SIZE_AFTER_SAPLING) return state.DoS(100, error("CheckTransaction(): size limits failed"), @@ -1807,9 +1807,9 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa uint32_t tiptime; int flag=0,nextBlockHeight = chainActive.Height() + 1; auto consensusBranchId = CurrentEpochBranchId(nextBlockHeight, Params().GetConsensus()); - if ( nextBlockHeight <= 1 || chainActive.LastTip() == 0 ) + if ( nextBlockHeight <= 1 || chainActive.Tip() == 0 ) tiptime = (uint32_t)time(NULL); - else tiptime = (uint32_t)chainActive.LastTip()->nTime; + else tiptime = (uint32_t)chainActive.Tip()->nTime; //fprintf(stderr,"addmempool 0\n"); // Node operator can choose to reject tx by number of transparent inputs static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), "size_t too small"); @@ -1826,7 +1826,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } //fprintf(stderr,"addmempool 1\n"); auto verifier = libzcash::ProofVerifier::Strict(); - if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,chainActive.LastTip()->GetHeight()+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,chainActive.Tip()->GetHeight()+1,chainActive.Tip()->GetMedianTimePast() + 777,0) < 0 ) { fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); @@ -1964,7 +1964,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Bring the best block into scope view.GetBestBlock(); - nValueIn = view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime); + nValueIn = view.GetValueIn(chainActive.Tip()->GetHeight(),&interest,tx,chainActive.Tip()->nTime); if ( 0 && interest != 0 ) fprintf(stderr,"add interest %.8f\n",(double)interest/COIN); // we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool @@ -2088,10 +2088,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // invalid blocks, however allowing such transactions into the mempool // can be exploited as a DoS attack. // XXX: is this neccesary for CryptoConditions? - if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) + if ( KOMODO_CONNECTING <= 0 && chainActive.Tip() != 0 ) { flag = 1; - KOMODO_CONNECTING = (1<<30) + (int32_t)chainActive.LastTip()->GetHeight() + 1; + KOMODO_CONNECTING = (1<<30) + (int32_t)chainActive.Tip()->GetHeight() + 1; } //fprintf(stderr,"addmempool 7\n"); @@ -2607,7 +2607,7 @@ void CheckForkWarningConditions() if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->GetHeight() >= 288) pindexBestForkTip = NULL; - if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->chainPower > (chainActive.LastTip()->chainPower + (GetBlockProof(*chainActive.LastTip()) * 6)))) + if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->chainPower > (chainActive.Tip()->chainPower + (GetBlockProof(*chainActive.Tip()) * 6)))) { if (!fLargeWorkForkFound && pindexBestForkBase) { @@ -2642,7 +2642,7 @@ void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip) AssertLockHeld(cs_main); // If we are on a fork that is sufficiently large, set a warning flag CBlockIndex* pfork = pindexNewForkTip; - CBlockIndex* plonger = chainActive.LastTip(); + CBlockIndex* plonger = chainActive.Tip(); while (pfork && pfork != plonger) { while (plonger && plonger->GetHeight() > pfork->GetHeight()) @@ -2700,7 +2700,7 @@ void static InvalidChainFound(CBlockIndex* pindexNew) log(pindexNew->chainPower.chainWork.getdouble())/log(2.0), log(pindexNew->chainPower.chainStake.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexNew->GetBlockTime())); - CBlockIndex *tip = chainActive.LastTip(); + CBlockIndex *tip = chainActive.Tip(); assert (tip); LogPrintf("%s: current best=%s height=%d log2_work=%.8g log2_stake=%.8g date=%s\n", __func__, tip->GetBlockHash().ToString(), chainActive.Height(), @@ -2846,14 +2846,14 @@ namespace Consensus { // Check for negative or overflow input values nValueIn += coins->vout[prevout.n].nValue; #ifdef KOMODO_ENABLE_INTEREST - if ( ASSETCHAINS_SYMBOL[0] == 0 && nSpendHeight > 60000 )//chainActive.LastTip() != 0 && chainActive.LastTip()->GetHeight() >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && nSpendHeight > 60000 )//chainActive.Tip() != 0 && chainActive.Tip()->GetHeight() >= 60000 ) { if ( coins->vout[prevout.n].nValue >= 10*COIN ) { int64_t interest; int32_t txheight; uint32_t locktime; if ( (interest= komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue,(int32_t)nSpendHeight-1)) != 0 ) { - //fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.LastTip()->nTime); + //fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); nValueIn += interest; } } @@ -3689,7 +3689,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return state.DoS(100, error("ConnectBlock(): voutsum less after adding valueout"),REJECT_INVALID,"tx valueout is too big");*/ if (!tx.IsCoinBase()) { - nFees += (stakeTxValue= view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime) - valueout); + nFees += (stakeTxValue= view.GetValueIn(chainActive.Tip()->GetHeight(),&interest,tx,chainActive.Tip()->nTime) - valueout); sum += interest; //fprintf(stderr, "tx.%s nFees.%li interest.%li\n", tx.GetHash().ToString().c_str(), stakeTxValue, interest); @@ -4045,18 +4045,18 @@ void static UpdateTip(CBlockIndex *pindexNew) { KOMODO_NEWBLOCKS++; double progress; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip()); + progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()); } else { int32_t longestchain = komodo_longestchain(); progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; } LogPrintf("%s: new best=%s height=%d log2_work=%.8g log2_stake=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, - chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(), + chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->chainPower.chainWork.getdouble())/log(2.0), log(chainActive.Tip()->chainPower.chainStake.getdouble())/log(2.0), - (unsigned long)chainActive.LastTip()->nChainTx, - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.LastTip()->GetBlockTime()), progress, + (unsigned long)chainActive.Tip()->nChainTx, + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), progress, pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); cvBlockChange.notify_all(); @@ -4443,7 +4443,7 @@ static void PruneBlockIndexCandidates() { // Note that we can't delete the current block itself, as we may need to return to it later in case a // reorganization to a better block fails. std::set::iterator it = setBlockIndexCandidates.begin(); - while (it != setBlockIndexCandidates.end() && setBlockIndexCandidates.value_comp()(*it, chainActive.LastTip())) { + while (it != setBlockIndexCandidates.end() && setBlockIndexCandidates.value_comp()(*it, chainActive.Tip())) { setBlockIndexCandidates.erase(it++); } // Either the current tip or a successor of it we're working towards is left in setBlockIndexCandidates. @@ -4538,8 +4538,8 @@ static bool ActivateBestChainStep(bool fSkipdpow, CValidationState &state, CBloc if ( KOMODO_REWIND != 0 ) { CBlockIndex *tipindex; - fprintf(stderr,">>>>>>>>>>> rewind start ht.%d -> KOMODO_REWIND.%d\n",chainActive.LastTip()->GetHeight(),KOMODO_REWIND); - while ( KOMODO_REWIND > 0 && (tipindex= chainActive.LastTip()) != 0 && tipindex->GetHeight() > KOMODO_REWIND ) + fprintf(stderr,">>>>>>>>>>> rewind start ht.%d -> KOMODO_REWIND.%d\n",chainActive.Tip()->GetHeight(),KOMODO_REWIND); + while ( KOMODO_REWIND > 0 && (tipindex= chainActive.Tip()) != 0 && tipindex->GetHeight() > KOMODO_REWIND ) { fBlocksDisconnected = true; fprintf(stderr,"%d ",(int32_t)tipindex->GetHeight()); @@ -5076,9 +5076,9 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- CheckBlockHeader\n"); - if ( chainActive.LastTip() != 0 ) + if ( chainActive.Tip() != 0 ) { - hash = chainActive.LastTip()->GetBlockHash(); + hash = chainActive.Tip()->GetBlockHash(); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- chainTip\n"); @@ -5397,7 +5397,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta // Don't accept any forks from the main chain prior to last checkpoint CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; - if ( nHeight == 1 && chainActive.LastTip() != 0 && chainActive.LastTip()->GetHeight() > 1 ) + if ( nHeight == 1 && chainActive.Tip() != 0 && chainActive.Tip()->GetHeight() > 1 ) { CBlockIndex *heightblock = chainActive[nHeight]; if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) @@ -5617,7 +5617,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C if ( saplinght < 0 ) *futureblockp = 1; // the problem is when a future sapling block comes in before we detected saplinght - if ( saplinght > 0 && (tmpptr= chainActive.LastTip()) != 0 ) + if ( saplinght > 0 && (tmpptr= chainActive.Tip()) != 0 ) { fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+50000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); if ( pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+50000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) @@ -5782,11 +5782,11 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo bool checked; uint256 hash; int32_t futureblock=0; auto verifier = libzcash::ProofVerifier::Disabled(); hash = pblock->GetHash(); - //fprintf(stderr,"ProcessBlock %d\n",(int32_t)chainActive.LastTip()->GetHeight()); + //fprintf(stderr,"ProcessBlock %d\n",(int32_t)chainActive.Tip()->GetHeight()); { LOCK(cs_main); - if ( chainActive.LastTip() != 0 ) - komodo_currentheight_set(chainActive.LastTip()->GetHeight()); + if ( chainActive.Tip() != 0 ) + komodo_currentheight_set(chainActive.Tip()->GetHeight()); checked = CheckBlock(&futureblock,height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); bool fRequested = MarkBlockAsReceived(hash); fRequested |= fForceProcessing; @@ -5816,7 +5816,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo /*if ( ASSETCHAINS_SYMBOL[0] == 0 ) { //fprintf(stderr,"request headers from failed process block peer\n"); - pfrom->PushMessage("getheaders", chainActive.GetLocator(chainActive.LastTip()), uint256()); + pfrom->PushMessage("getheaders", chainActive.GetLocator(chainActive.Tip()), uint256()); }*/ komodo_longestchain(); return error("%s: AcceptBlock FAILED", __func__); @@ -5826,7 +5826,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo if (futureblock == 0 && !ActivateBestChain(false, state, pblock)) return error("%s: ActivateBestChain failed", __func__); - //fprintf(stderr,"finished ProcessBlock %d\n",(int32_t)chainActive.LastTip()->GetHeight()); + //fprintf(stderr,"finished ProcessBlock %d\n",(int32_t)chainActive.Tip()->GetHeight()); return true; } @@ -6268,7 +6268,7 @@ bool static LoadBlockIndexDB() double progress; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - progress = Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.LastTip()); + progress = Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip()); } else { int32_t longestchain = komodo_longestchain(); // TODO: komodo_longestchain does not have the data it needs at the time LoadBlockIndexDB @@ -6276,13 +6276,13 @@ bool static LoadBlockIndexDB() progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 0.5; } LogPrintf("%s: hashBestChain=%s height=%d date=%s progress=%f\n", __func__, - chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(), - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.LastTip()->GetBlockTime()), + chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), progress); EnforceNodeDeprecation(chainActive.Height(), true); CBlockIndex *pindex; - if ( (pindex= chainActive.LastTip()) != 0 ) + if ( (pindex= chainActive.Tip()) != 0 ) { if ( ASSETCHAINS_SAPLING <= 0 ) { @@ -7709,7 +7709,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, LOCK(cs_main); - if (chainActive.LastTip() != 0 && chainActive.LastTip()->GetHeight() > 100000 && IsInitialBlockDownload()) + if (chainActive.Tip() != 0 && chainActive.Tip()->GetHeight() > 100000 && IsInitialBlockDownload()) { //fprintf(stderr,"dont process getheaders during initial download\n"); return true; diff --git a/src/metrics.cpp b/src/metrics.cpp index 1fa8ebfb5b0..ff548ffb61f 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -246,7 +246,7 @@ int printStats(bool mining) { LOCK2(cs_main, cs_vNodes); height = chainActive.Height(); - tipmediantime = chainActive.LastTip()->GetMedianTimePast(); + tipmediantime = chainActive.Tip()->GetMedianTimePast(); connections = vNodes.size(); netsolps = GetNetworkHashPS(120, -1); } diff --git a/src/miner.cpp b/src/miner.cpp index 2130f90de14..709aadaa372 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -173,7 +173,7 @@ int32_t komodo_waituntilelegible(uint32_t blocktime, int32_t stakeHeight, uint32 break; if ( (rand() % 100) < 2-(secToElegible>ASSETCHAINS_STAKED_BLOCK_FUTURE_MAX) ) fprintf(stderr, "[%s:%i] %llds until elegible...\n", ASSETCHAINS_SYMBOL, stakeHeight, (long long)secToElegible); - if ( chainActive.LastTip()->GetHeight() >= stakeHeight ) + if ( chainActive.Tip()->GetHeight() >= stakeHeight ) { fprintf(stderr, "[%s:%i] Chain advanced, reset staking loop.\n", ASSETCHAINS_SYMBOL, stakeHeight); return(0); @@ -228,9 +228,9 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 pblocktemplate->vTxSigOps.push_back(-1); // updated at end // Largest block you're willing to create: - unsigned int nBlockMaxSize = GetArg("-blockmaxsize", MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1)); + unsigned int nBlockMaxSize = GetArg("-blockmaxsize", MAX_BLOCK_SIZE(chainActive.Tip()->GetHeight()+1)); // Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity: - nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1)-1000), nBlockMaxSize)); + nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE(chainActive.Tip()->GetHeight()+1)-1000), nBlockMaxSize)); // How much of the block should be dedicated to high-priority transactions, // included regardless of the fees they pay @@ -259,7 +259,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 boost::this_thread::disable_interruption(); ENTER_CRITICAL_SECTION(cs_main); ENTER_CRITICAL_SECTION(mempool.cs); - pindexPrev = chainActive.LastTip(); + pindexPrev = chainActive.Tip(); const int nHeight = pindexPrev->GetHeight() + 1; const Consensus::Params &consensusParams = chainparams.GetConsensus(); uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, consensusParams); @@ -568,7 +568,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //fprintf(stderr,"dont have inputs\n"); continue; } - CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut(); + CAmount nTxFees = view.GetValueIn(chainActive.Tip()->GetHeight(),&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut(); nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) @@ -697,7 +697,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; 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))); + //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } @@ -714,7 +714,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //fprintf(stderr, "MINER: coinbasetx.%s\n", EncodeHexTx(txNew).c_str()); //fprintf(stderr,"mine ht.%d with %.8f\n",nHeight,(double)txNew.vout[0].nValue/COIN); - //if ((uint32_t)chainActive.LastTip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) { + //if ((uint32_t)chainActive.Tip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) { if ( ASSETCHAINS_ADAPTIVEPOW <= 0 ) txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetTime()); else txNew.nLockTime = std::max((int64_t)(pindexPrev->nTime+1), GetTime()); @@ -1088,18 +1088,18 @@ static bool ProcessBlockFound(CBlock* pblock) #endif // ENABLE_WALLET { LogPrintf("%s\n", pblock->ToString()); - LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.LastTip()->GetHeight()+1); + LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.Tip()->GetHeight()+1); // Found a solution { - if (pblock->hashPrevBlock != chainActive.LastTip()->GetBlockHash()) + if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash()) { uint256 hash; int32_t i; hash = pblock->hashPrevBlock; for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- prev (stale)\n"); - hash = chainActive.LastTip()->GetBlockHash(); + hash = chainActive.Tip()->GetBlockHash(); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- chainTip (stale)\n"); @@ -1129,7 +1129,7 @@ static bool ProcessBlockFound(CBlock* pblock) // Process this block the same as if we had received it from another node CValidationState state; - if (!ProcessNewBlock(1,chainActive.LastTip()->GetHeight()+1,state, NULL, pblock, true, NULL)) + if (!ProcessNewBlock(1,chainActive.Tip()->GetHeight()+1,state, NULL, pblock, true, NULL)) return error("KomodoMiner: ProcessNewBlock, block not accepted"); TrackMinedBlock(pblock->GetHash()); @@ -1193,9 +1193,9 @@ void waitForPeers(const CChainParams &chainparams) #ifdef ENABLE_WALLET CBlockIndex *get_chainactive(int32_t height) { - if ( chainActive.LastTip() != 0 ) + if ( chainActive.Tip() != 0 ) { - if ( height <= chainActive.LastTip()->GetHeight() ) + if ( height <= chainActive.Tip()->GetHeight() ) { LOCK(cs_main); return(chainActive[height]); @@ -1236,17 +1236,17 @@ void static VerusStaker(CWallet *pwallet) // try a nice clean peer connection to start CBlockIndex *pindexPrev, *pindexCur; do { - pindexPrev = chainActive.LastTip(); + pindexPrev = chainActive.Tip(); MilliSleep(5000 + rand() % 5000); waitForPeers(chainparams); - pindexCur = chainActive.LastTip(); + pindexCur = chainActive.Tip(); } while (pindexPrev != pindexCur); try { while (true) { waitForPeers(chainparams); - CBlockIndex* pindexPrev = chainActive.LastTip(); + CBlockIndex* pindexPrev = chainActive.Tip(); printf("Staking height %d for %s\n", pindexPrev->GetHeight() + 1, ASSETCHAINS_SYMBOL); // Create new block @@ -1268,7 +1268,7 @@ void static VerusStaker(CWallet *pwallet) if ( ptr == 0 ) { // wait to try another staking block until after the tip moves again - while ( chainActive.LastTip() == pindexPrev ) + while ( chainActive.Tip() == pindexPrev ) sleep(1); continue; } @@ -1315,9 +1315,9 @@ void static VerusStaker(CWallet *pwallet) continue; } - if ( pindexPrev != chainActive.LastTip() ) + if ( pindexPrev != chainActive.Tip() ) { - printf("Block %d added to chain\n", chainActive.LastTip()->GetHeight()); + printf("Block %d added to chain\n", chainActive.Tip()->GetHeight()); MilliSleep(250); continue; } @@ -1403,10 +1403,10 @@ void static BitcoinMiner_noeq() // try a nice clean peer connection to start CBlockIndex *pindexPrev, *pindexCur; do { - pindexPrev = chainActive.LastTip(); + pindexPrev = chainActive.Tip(); MilliSleep(5000 + rand() % 5000); waitForPeers(chainparams); - pindexCur = chainActive.LastTip(); + pindexCur = chainActive.Tip(); } while (pindexPrev != pindexCur); // this will not stop printing more than once in all cases, but it will allow us to print in all cases @@ -1422,16 +1422,16 @@ void static BitcoinMiner_noeq() miningTimer.stop(); waitForPeers(chainparams); - pindexPrev = chainActive.LastTip(); + pindexPrev = chainActive.Tip(); sleep(1); // prevent forking on startup before the diff algorithm kicks in - if (pindexPrev->GetHeight() < 50 || pindexPrev != chainActive.LastTip()) + if (pindexPrev->GetHeight() < 50 || pindexPrev != chainActive.Tip()) { do { - pindexPrev = chainActive.LastTip(); + pindexPrev = chainActive.Tip(); MilliSleep(5000 + rand() % 5000); - } while (pindexPrev != chainActive.LastTip()); + } while (pindexPrev != chainActive.Tip()); } // Create new block @@ -1506,11 +1506,11 @@ void static BitcoinMiner_noeq() Mining_start = 0; - if ( pindexPrev != chainActive.LastTip() ) + if ( pindexPrev != chainActive.Tip() ) { - if (lastChainTipPrinted != chainActive.LastTip()) + if (lastChainTipPrinted != chainActive.Tip()) { - lastChainTipPrinted = chainActive.LastTip(); + lastChainTipPrinted = chainActive.Tip(); printf("Block %d added to chain\n", lastChainTipPrinted->GetHeight()); } MilliSleep(250); @@ -1607,11 +1607,11 @@ void static BitcoinMiner_noeq() // check periodically if we're stale if (!--hashesToGo) { - if ( pindexPrev != chainActive.LastTip() ) + if ( pindexPrev != chainActive.Tip() ) { - if (lastChainTipPrinted != chainActive.LastTip()) + if (lastChainTipPrinted != chainActive.Tip()) { - lastChainTipPrinted = chainActive.LastTip(); + lastChainTipPrinted = chainActive.Tip(); printf("Block %d added to chain\n", lastChainTipPrinted->GetHeight()); } break; @@ -1643,11 +1643,11 @@ void static BitcoinMiner_noeq() break; } - if ( pindexPrev != chainActive.LastTip() ) + if ( pindexPrev != chainActive.Tip() ) { - if (lastChainTipPrinted != chainActive.LastTip()) + if (lastChainTipPrinted != chainActive.Tip()) { - lastChainTipPrinted = chainActive.LastTip(); + lastChainTipPrinted = chainActive.Tip(); printf("Block %d added to chain\n", lastChainTipPrinted->GetHeight()); } break; @@ -1684,7 +1684,7 @@ extern int32_t getkmdseason(int32_t height); CBlockIndex * GetLastTipWithLock() { LOCK(cs_main); - return chainActive.LastTip(); + return chainActive.Tip(); } #ifdef ENABLE_WALLET @@ -2004,7 +2004,7 @@ void static BitcoinMiner() { LOCK(cs_main); CValidationState state; - blockValid = TestBlockValidity(state, B, chainActive.LastTip(), true, false); + blockValid = TestBlockValidity(state, B, chainActive.Tip(), true, false); } if ( !blockValid ) { diff --git a/src/rest.cpp b/src/rest.cpp index 3fb87f8f386..10fa6507375 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -548,7 +548,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) // serialize data // use exact same output as mentioned in Bip64 CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); - ssGetUTXOResponse << chainActive.Height() << chainActive.LastTip()->GetBlockHash() << bitmap << outs; + ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs; string ssGetUTXOResponseString = ssGetUTXOResponse.str(); req->WriteHeader("Content-Type", "application/octet-stream"); @@ -558,7 +558,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) case RF_HEX: { CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); - ssGetUTXOResponse << chainActive.Height() << chainActive.LastTip()->GetBlockHash() << bitmap << outs; + ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs; string strHex = HexStr(ssGetUTXOResponse.begin(), ssGetUTXOResponse.end()) + "\n"; req->WriteHeader("Content-Type", "text/plain"); @@ -572,7 +572,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) // pack in some essentials // use more or less the same output as mentioned in Bip64 objGetUTXOResponse.push_back(Pair("chainHeight", chainActive.Height())); - objGetUTXOResponse.push_back(Pair("chaintipHash", chainActive.LastTip()->GetBlockHash().GetHex())); + objGetUTXOResponse.push_back(Pair("chaintipHash", chainActive.Tip()->GetBlockHash().GetHex())); objGetUTXOResponse.push_back(Pair("bitmap", bitmapStringRepresentation)); UniValue utxos(UniValue::VARR); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 38124042861..cdbb919323d 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -61,10 +61,10 @@ double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficul // minimum difficulty = 1.0. if (blockindex == NULL) { - if (chainActive.LastTip() == NULL) + if (chainActive.Tip() == NULL) return 1.0; else - blockindex = chainActive.LastTip(); + blockindex = chainActive.Tip(); } uint32_t bits; @@ -370,7 +370,7 @@ UniValue getbestblockhash(const UniValue& params, bool fHelp, const CPubKey& myp ); LOCK(cs_main); - return chainActive.LastTip()->GetBlockHash().GetHex(); + return chainActive.Tip()->GetBlockHash().GetHex(); } UniValue getdifficulty(const UniValue& params, bool fHelp, const CPubKey& mypk) @@ -960,13 +960,13 @@ UniValue kvsearch(const UniValue& params, bool fHelp, const CPubKey& mypk) if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - ret.push_back(Pair("currentheight", (int64_t)chainActive.LastTip()->GetHeight())); + ret.push_back(Pair("currentheight", (int64_t)chainActive.Tip()->GetHeight())); ret.push_back(Pair("key",params[0].get_str())); ret.push_back(Pair("keylen",keylen)); if ( keylen < sizeof(key) ) { memcpy(key,params[0].get_str().c_str(),keylen); - if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->GetHeight(),&flags,&height,value,key,keylen)) >= 0 ) + if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->GetHeight(),&flags,&height,value,key,keylen)) >= 0 ) { std::string val; char *valuestr; val.resize(valuesize); @@ -994,7 +994,7 @@ UniValue minerids(const UniValue& params, bool fHelp, const CPubKey& mypk) LOCK(cs_main); int32_t height = atoi(params[0].get_str().c_str()); if ( height <= 0 ) - height = chainActive.LastTip()->GetHeight(); + height = chainActive.Tip()->GetHeight(); else { CBlockIndex *pblockindex = chainActive[height]; @@ -1056,8 +1056,8 @@ UniValue notaries(const UniValue& params, bool fHelp, const CPubKey& mypk) else timestamp = (uint32_t)time(NULL); if ( height < 0 ) { - height = chainActive.LastTip()->GetHeight(); - timestamp = chainActive.LastTip()->GetBlockTime(); + height = chainActive.Tip()->GetHeight(); + timestamp = chainActive.Tip()->GetBlockTime(); } else if ( params.size() < 2 ) { @@ -1145,7 +1145,7 @@ UniValue paxprice(const UniValue& params, bool fHelp, const CPubKey& mypk) std::string rel = params[1].get_str(); int32_t height; if ( params.size() == 2 ) - height = chainActive.LastTip()->GetHeight(); + height = chainActive.Tip()->GetHeight(); else height = atoi(params[2].get_str().c_str()); //if ( params.size() == 3 || (basevolume= COIN * atof(params[3].get_str().c_str())) == 0 ) basevolume = 100000; @@ -1713,7 +1713,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp, const CPubKey& my LOCK(cs_main); double progress; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - progress = Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.LastTip()); + progress = Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip()); } else { int32_t longestchain = KOMODO_LONGESTCHAIN;//komodo_longestchain(); progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; @@ -1723,13 +1723,13 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp, const CPubKey& my obj.push_back(Pair("blocks", (int)chainActive.Height())); obj.push_back(Pair("synced", KOMODO_INSYNC!=0)); obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->GetHeight() : -1)); - obj.push_back(Pair("bestblockhash", chainActive.LastTip()->GetBlockHash().GetHex())); + obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex())); obj.push_back(Pair("difficulty", (double)GetNetworkDifficulty())); obj.push_back(Pair("verificationprogress", progress)); - obj.push_back(Pair("chainwork", chainActive.LastTip()->chainPower.chainWork.GetHex())); + obj.push_back(Pair("chainwork", chainActive.Tip()->chainPower.chainWork.GetHex())); if (ASSETCHAINS_LWMAPOS) { - obj.push_back(Pair("chainstake", chainActive.LastTip()->chainPower.chainStake.GetHex())); + obj.push_back(Pair("chainstake", chainActive.Tip()->chainPower.chainStake.GetHex())); } obj.push_back(Pair("pruned", fPruneMode)); @@ -1737,7 +1737,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp, const CPubKey& my pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), tree); obj.push_back(Pair("commitments", static_cast(tree.size()))); - CBlockIndex* tip = chainActive.LastTip(); + CBlockIndex* tip = chainActive.Tip(); UniValue valuePools(UniValue::VARR); valuePools.push_back(ValuePoolDesc("sprout", tip->nChainSproutValue, boost::none)); valuePools.push_back(ValuePoolDesc("sapling", tip->nChainSaplingValue, boost::none)); @@ -1763,7 +1763,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp, const CPubKey& my if (fPruneMode) { - CBlockIndex *block = chainActive.LastTip(); + CBlockIndex *block = chainActive.Tip(); while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) block = block->pprev; @@ -1856,7 +1856,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp, const CPubKey& mypk) //pthread_mutex_unlock(&mutex); // Always report the currently active tip. - setTips.insert(chainActive.LastTip()); + setTips.insert(chainActive.Tip()); /* Construct the output array. */ UniValue res(UniValue::VARR); const CBlockIndex *forked; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index d2e891556c2..fe84224fbd2 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -63,7 +63,7 @@ int32_t komodo_newStakerActive(int32_t height, uint32_t timestamp); */ int64_t GetNetworkHashPS(int lookup, int height) { - CBlockIndex *pb = chainActive.LastTip(); + CBlockIndex *pb = chainActive.Tip(); if (height >= 0 && height < chainActive.Height()) pb = chainActive[height]; @@ -271,7 +271,7 @@ UniValue generate(const UniValue& params, bool fHelp, const CPubKey& mypk) CBlock *pblock = &pblocktemplate->block; { LOCK(cs_main); - IncrementExtraNonce(pblock, chainActive.LastTip(), nExtraNonce); + IncrementExtraNonce(pblock, chainActive.Tip(), nExtraNonce); } // Hash state @@ -315,7 +315,7 @@ UniValue generate(const UniValue& params, bool fHelp, const CPubKey& mypk) } endloop: CValidationState state; - if (!ProcessNewBlock(1,chainActive.LastTip()->GetHeight()+1,state, NULL, pblock, true, NULL)) + if (!ProcessNewBlock(1,chainActive.Tip()->GetHeight()+1,state, NULL, pblock, true, NULL)) throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted"); ++nHeight; blockHashes.push_back(pblock->GetHash().GetHex()); @@ -686,7 +686,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp return "duplicate-inconclusive"; } - CBlockIndex* const pindexPrev = chainActive.LastTip(); + CBlockIndex* const pindexPrev = chainActive.Tip(); // TestBlockValidity only supports blocks built on the current Tip if (block.hashPrevBlock != pindexPrev->GetBlockHash()) return "inconclusive-not-best-prevblk"; @@ -736,7 +736,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp else { // NOTE: Spec does not specify behaviour for non-string longpollid, but this makes testing easier - hashWatchedChain = chainActive.LastTip()->GetBlockHash(); + hashWatchedChain = chainActive.Tip()->GetBlockHash(); nTransactionsUpdatedLastLP = nTransactionsUpdatedLast; } @@ -746,7 +746,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp checktxtime = boost::get_system_time() + boost::posix_time::minutes(1); boost::unique_lock lock(csBestBlock); - while (chainActive.LastTip()->GetBlockHash() == hashWatchedChain && IsRPCRunning()) + while (chainActive.Tip()->GetBlockHash() == hashWatchedChain && IsRPCRunning()) { if (!cvBlockChange.timed_wait(lock, checktxtime)) { @@ -768,7 +768,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp static CBlockIndex* pindexPrev; static int64_t nStart; static CBlockTemplate* pblocktemplate; - if (pindexPrev != chainActive.LastTip() || + if (pindexPrev != chainActive.Tip() || (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5)) { // Clear pindexPrev so future calls make a new block, despite any failures from here on @@ -776,7 +776,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp // Store the pindexBest used before CreateNewBlockWithKey, to avoid races nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); - CBlockIndex* pindexPrevNew = chainActive.LastTip(); + CBlockIndex* pindexPrevNew = chainActive.Tip(); nStart = GetTime(); // Create new block @@ -843,7 +843,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp // Correct this if GetBlockTemplate changes the order entry.push_back(Pair("foundersreward", (int64_t)tx.vout[1].nValue)); } - CAmount nReward = GetBlockSubsidy(chainActive.LastTip()->GetHeight()+1, Params().GetConsensus()); + CAmount nReward = GetBlockSubsidy(chainActive.Tip()->GetHeight()+1, Params().GetConsensus()); entry.push_back(Pair("coinbasevalue", nReward)); entry.push_back(Pair("required", true)); txCoinbase = entry; @@ -877,7 +877,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp // result.push_back(Pair("coinbaseaux", aux)); // result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue)); //} - result.push_back(Pair("longpollid", chainActive.LastTip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); + result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); if ( ASSETCHAINS_STAKED != 0 ) { arith_uint256 POWtarget; int32_t PoSperc; @@ -895,7 +895,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp result.push_back(Pair("mutable", aMutable)); result.push_back(Pair("noncerange", "00000000ffffffff")); result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS)); - result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1))); + result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE(chainActive.Tip()->GetHeight()+1))); result.push_back(Pair("curtime", pblock->GetBlockTime())); result.push_back(Pair("bits", strprintf("%08x", pblock->nBits))); result.push_back(Pair("height", (int64_t)(pindexPrev->GetHeight()+1))); @@ -977,8 +977,8 @@ UniValue submitblock(const UniValue& params, bool fHelp, const CPubKey& mypk) CValidationState state; submitblock_StateCatcher sc(block.GetHash()); RegisterValidationInterface(&sc); - //printf("submitblock, height=%d, coinbase sequence: %d, scriptSig: %s\n", chainActive.LastTip()->GetHeight()+1, block.vtx[0].vin[0].nSequence, block.vtx[0].vin[0].scriptSig.ToString().c_str()); - bool fAccepted = ProcessNewBlock(1,chainActive.LastTip()->GetHeight()+1,state, NULL, &block, true, NULL); + //printf("submitblock, height=%d, coinbase sequence: %d, scriptSig: %s\n", chainActive.Tip()->GetHeight()+1, block.vtx[0].vin[0].nSequence, block.vtx[0].vin[0].scriptSig.ToString().c_str()); + bool fAccepted = ProcessNewBlock(1,chainActive.Tip()->GetHeight()+1,state, NULL, &block, true, NULL); UnregisterValidationInterface(&sc); if (fBlockPresent) { diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index b111ef4a4e0..4e1696fbaad 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -177,7 +177,7 @@ UniValue geterablockheights(const UniValue& params, bool fHelp, const CPubKey& m CBlockIndex *pindex; int8_t lastera,era = 0; UniValue ret(UniValue::VOBJ); - for (size_t i = 1; i < chainActive.LastTip()->GetHeight(); i++) + for (size_t i = 1; i < chainActive.Tip()->GetHeight(); i++) { pindex = chainActive[i]; era = getera(pindex->nTime)+1; @@ -274,8 +274,8 @@ UniValue getinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) longestchain = chainActive.Height(); //fprintf(stderr,"after longestchain %u\n",(uint32_t)time(NULL)); obj.push_back(Pair("longestchain", longestchain)); - if ( chainActive.LastTip() != 0 ) - obj.push_back(Pair("tiptime", (int)chainActive.LastTip()->nTime)); + if ( chainActive.Tip() != 0 ) + obj.push_back(Pair("tiptime", (int)chainActive.Tip()->nTime)); obj.push_back(Pair("difficulty", (double)GetDifficulty())); #ifdef ENABLE_WALLET if (pwalletMain) { @@ -299,7 +299,7 @@ UniValue getinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) if ( (notaryid= StakedNotaryID(notaryname, (char *)NOTARY_ADDRESS.c_str())) != -1 ) { obj.push_back(Pair("notaryid", notaryid)); obj.push_back(Pair("notaryname", notaryname)); - } else if( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.LastTip()->GetHeight(),komodo_chainactive_timestamp())) >= 0 ) { + } else if( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.Tip()->GetHeight(),komodo_chainactive_timestamp())) >= 0 ) { obj.push_back(Pair("notaryid", notaryid)); if ( KOMODO_LASTMINED != 0 ) obj.push_back(Pair("lastmined", KOMODO_LASTMINED)); @@ -1089,7 +1089,7 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp, const CPubKey& mypk result.push_back(Pair("utxos", utxos)); LOCK(cs_main); - result.push_back(Pair("hash", chainActive.LastTip()->GetBlockHash().GetHex())); + result.push_back(Pair("hash", chainActive.Tip()->GetBlockHash().GetHex())); result.push_back(Pair("height", (int)chainActive.Height())); return result; } else { @@ -1239,7 +1239,7 @@ CAmount checkburnaddress(CAmount &received, int64_t &nNotaryPay, int32_t &height balance += it->second; } // Get notary pay from current chain tip - CBlockIndex* pindex = chainActive.LastTip(); + CBlockIndex* pindex = chainActive.Tip(); nNotaryPay = pindex->nNotaryPay; height = pindex->GetHeight(); } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index eaf1ec002c5..3cebaa1bea6 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -272,7 +272,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& const CTxOut& txout = tx.vout[i]; UniValue out(UniValue::VOBJ); out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - if ( ASSETCHAINS_SYMBOL[0] == 0 && pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.Tip()) != 0 ) { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->GetHeight()); @@ -374,7 +374,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) const CTxOut& txout = tx.vout[i]; UniValue out(UniValue::VOBJ); out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - if ( KOMODO_NSPV_FULLNODE && ASSETCHAINS_SYMBOL[0] == 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 ) + if ( KOMODO_NSPV_FULLNODE && ASSETCHAINS_SYMBOL[0] == 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.Tip()) != 0 ) { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->GetHeight()); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index a60a8103a65..40fcde28be2 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -520,7 +520,7 @@ void CTxMemPool::removeExpired(unsigned int nBlockHeight) for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { const CTransaction& tx = it->GetTx(); - tipindex = chainActive.LastTip(); + tipindex = chainActive.Tip(); bool fInterestNotValidated = ASSETCHAINS_SYMBOL[0] == 0 && tipindex != 0 && komodo_validate_interest(tx,tipindex->GetHeight()+1,tipindex->GetMedianTimePast() + 777,0) < 0; if (IsExpiredTx(tx, nBlockHeight) || fInterestNotValidated) diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index dca93461be0..08f22a7127d 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -376,8 +376,8 @@ bool AsyncRPCOperation_sendmany::main_impl() { // locktime to spend time locked coinbases if (ASSETCHAINS_SYMBOL[0] == 0) { - //if ((uint32_t)chainActive.LastTip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) - if ( !komodo_hardfork_active((uint32_t)chainActive.LastTip()->nTime) ) + //if ((uint32_t)chainActive.Tip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) + if ( !komodo_hardfork_active((uint32_t)chainActive.Tip()->nTime) ) builder_.SetLockTime((uint32_t)time(NULL) - 60); // set lock time for Komodo interest else builder_.SetLockTime((uint32_t)chainActive.Tip()->GetMedianTimePast()); @@ -393,8 +393,8 @@ bool AsyncRPCOperation_sendmany::main_impl() { } if (ASSETCHAINS_SYMBOL[0] == 0) { - //if ((uint32_t)chainActive.LastTip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) - if ( !komodo_hardfork_active((uint32_t)chainActive.LastTip()->nTime) ) + //if ((uint32_t)chainActive.Tip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) + if ( !komodo_hardfork_active((uint32_t)chainActive.Tip()->nTime) ) rawTx.nLockTime = (uint32_t)time(NULL) - 60; // jl777 else rawTx.nLockTime = (uint32_t)chainActive.Tip()->GetMedianTimePast(); @@ -599,8 +599,8 @@ bool AsyncRPCOperation_sendmany::main_impl() { CMutableTransaction mtx(tx_); crypto_sign_keypair(joinSplitPubKey_.begin(), joinSplitPrivKey_); mtx.joinSplitPubKey = joinSplitPubKey_; - //if ((uint32_t)chainActive.LastTip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) - if ( !komodo_hardfork_active((uint32_t)chainActive.LastTip()->nTime) ) + //if ((uint32_t)chainActive.Tip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) + if ( !komodo_hardfork_active((uint32_t)chainActive.Tip()->nTime) ) mtx.nLockTime = (uint32_t)time(NULL) - 60; // jl777 else mtx.nLockTime = (uint32_t)chainActive.Tip()->GetMedianTimePast(); @@ -1375,8 +1375,8 @@ void AsyncRPCOperation_sendmany::add_taddr_outputs_to_tx() { CTxOut out(nAmount, scriptPubKey); rawTx.vout.push_back(out); } - //if ((uint32_t)chainActive.LastTip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) - if ( !komodo_hardfork_active((uint32_t)chainActive.LastTip()->nTime) ) + //if ((uint32_t)chainActive.Tip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) + if ( !komodo_hardfork_active((uint32_t)chainActive.Tip()->nTime) ) rawTx.nLockTime = (uint32_t)time(NULL) - 60; // jl777 else rawTx.nLockTime = (uint32_t)chainActive.Tip()->GetMedianTimePast(); @@ -1406,8 +1406,8 @@ void AsyncRPCOperation_sendmany::add_taddr_change_output_to_tx(CBitcoinAddress * CMutableTransaction rawTx(tx_); rawTx.vout.push_back(out); - //if ((uint32_t)chainActive.LastTip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) - if ( !komodo_hardfork_active((uint32_t)chainActive.LastTip()->nTime) ) + //if ((uint32_t)chainActive.Tip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) + if ( !komodo_hardfork_active((uint32_t)chainActive.Tip()->nTime) ) rawTx.nLockTime = (uint32_t)time(NULL) - 60; // jl777 else rawTx.nLockTime = (uint32_t)chainActive.Tip()->GetMedianTimePast(); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 4c8a9541ebe..19f1970d39e 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -409,7 +409,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys if (!file.is_open()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file"); - int64_t nTimeBegin = chainActive.LastTip()->GetBlockTime(); + int64_t nTimeBegin = chainActive.Tip()->GetBlockTime(); bool fGood = true; @@ -490,7 +490,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys file.close(); pwalletMain->ShowProgress("", 100); // hide progress dialog in GUI - CBlockIndex *pindex = chainActive.LastTip(); + CBlockIndex *pindex = chainActive.Tip(); while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - 7200) pindex = pindex->pprev; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fe861948563..9e68ba50827 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -534,7 +534,7 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) if ( ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 ) { - if ( komodo_isnotaryvout((char *)params[0].get_str().c_str(),chainActive.LastTip()->nTime) == 0 ) + if ( komodo_isnotaryvout((char *)params[0].get_str().c_str(),chainActive.Tip()->nTime) == 0 ) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); } @@ -658,7 +658,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk) valuesize = (int32_t)strlen(params[1].get_str().c_str()); } memcpy(keyvalue,key,keylen); - if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->GetHeight(),&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 ) + if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->GetHeight(),&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 ) { if ( (tmpflags & KOMODO_KVPROTECTED) != 0 ) { @@ -683,7 +683,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk) // printf("%02x",((uint8_t *)&sig)[i]); //printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - height = chainActive.LastTip()->GetHeight(); + height = chainActive.Tip()->GetHeight(); if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) ret.push_back(Pair("owner",refpubkey.GetHex())); ret.push_back(Pair("height", (int64_t)height)); @@ -755,7 +755,7 @@ UniValue paxdeposit(const UniValue& params, bool fHelp, const CPubKey& mypk) int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN; std::string base = params[2].get_str(); std::string dest; - height = chainActive.LastTip()->GetHeight(); + height = chainActive.Tip()->GetHeight(); if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,(char *)base.c_str()) != 0 || available < fiatoshis ) { fprintf(stderr,"available %llu vs fiatoshis %llu\n",(long long)available,(long long)fiatoshis); @@ -2975,16 +2975,16 @@ UniValue listunspent(const UniValue& params, bool fHelp, const CPubKey& mypk) BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *tipindex,*pindex = it->second; uint64_t interest; uint32_t locktime; - if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 ) + if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) { interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->GetHeight()); //interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); entry.push_back(Pair("interest",ValueFromAmount(interest))); } - //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->GetHeight()); + //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.Tip(),locktime,txheight,pindex->GetHeight()); } - else if ( chainActive.LastTip() != 0 ) - txheight = (chainActive.LastTip()->GetHeight() - out.nDepth - 1); + else if ( chainActive.Tip() != 0 ) + txheight = (chainActive.Tip()->GetHeight() - out.nDepth - 1); entry.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); entry.push_back(Pair("rawconfirmations",out.nDepth)); entry.push_back(Pair("confirmations",komodo_dpowconfs(txheight,out.nDepth))); @@ -3011,7 +3011,7 @@ uint64_t komodo_interestsum() { BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *tipindex,*pindex = it->second; - if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 ) + if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) { interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->GetHeight()); //interest = komodo_interest(pindex->GetHeight(),nValue,out.tx->nLockTime,tipindex->nTime); @@ -3744,7 +3744,7 @@ UniValue z_getnewaddress(const UniValue& params, bool fHelp, const CPubKey& mypk if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - bool allowSapling = (Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight <= chainActive.LastTip()->GetHeight()); + bool allowSapling = (Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight <= chainActive.Tip()->GetHeight()); std::string defaultType; if ( GetTime() < KOMODO_SAPLING_ACTIVATION ) @@ -4977,12 +4977,12 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp, const CPubKey& myp Params().GetConsensus(), nextBlockHeight, pwalletMain); // Contextual transaction we will build on - int blockHeight = chainActive.LastTip()->GetHeight(); + int blockHeight = chainActive.Tip()->GetHeight(); nextBlockHeight = blockHeight + 1; // (used if no Sapling addresses are involved) CMutableTransaction contextualTx = CreateNewContextualCMutableTransaction( Params().GetConsensus(), nextBlockHeight); - contextualTx.nLockTime = chainActive.LastTip()->GetHeight(); + contextualTx.nLockTime = chainActive.Tip()->GetHeight(); if (contextualTx.nVersion == 1) { contextualTx.nVersion = 2; // Tx format should support vjoinsplits diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b37669b5dbb..a1e87019902 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1395,7 +1395,7 @@ int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNe txnouttype whichType; std::vector> vSolutions; - CBlockIndex *tipindex = chainActive.LastTip(); + CBlockIndex *tipindex = chainActive.Tip(); uint32_t stakeHeight = tipindex->GetHeight() + 1; pk = CPubKey(); @@ -2892,7 +2892,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup double dProgressStart = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false); - double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip(), false); + double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip(), false); while (pindex) { if (pindex->GetHeight() % 100 == 0 && dProgressTip - dProgressStart > 0.0) @@ -3426,20 +3426,20 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if ( !IS_MODE_EXCHANGEWALLET ) { uint32_t locktime; int32_t txheight; CBlockIndex *tipindex; - if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && chainActive.LastTip()->GetHeight() >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && chainActive.Tip()->GetHeight() >= 60000 ) { if ( pcoin->vout[i].nValue >= 10*COIN ) { - if ( (tipindex= chainActive.LastTip()) != 0 ) + if ( (tipindex= chainActive.Tip()) != 0 ) { komodo_accrued_interest(&txheight,&locktime,wtxid,i,0,pcoin->vout[i].nValue,(int32_t)tipindex->GetHeight()); interest = komodo_interestnew(txheight,pcoin->vout[i].nValue,locktime,tipindex->nTime); } else interest = 0; - //interest = komodo_interestnew(chainActive.LastTip()->GetHeight()+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.LastTip()->nTime); + //interest = komodo_interestnew(chainActive.Tip()->GetHeight()+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); if ( interest != 0 ) { //printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u/%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,txheight,locktime,pcoin->nLockTime,tipindex->nTime); - //fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.LastTip()->GetHeight()+1,pcoin->nLockTime,chainActive.LastTip()->nTime); + //fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->GetHeight()+1,pcoin->nLockTime,chainActive.Tip()->nTime); //ptr = (uint64_t *)&pcoin->vout[i].nValue; //(*ptr) += interest; ptr = (uint64_t *)&pcoin->vout[i].interest; @@ -3789,9 +3789,9 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt int nextBlockHeight = chainActive.Height() + 1; CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextBlockHeight); - //if ((uint32_t)chainActive.LastTip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) - if ( !komodo_hardfork_active((uint32_t)chainActive.LastTip()->nTime) ) - txNew.nLockTime = (uint32_t)chainActive.LastTip()->nTime + 1; // set to a time close to now + //if ((uint32_t)chainActive.Tip()->nTime < ASSETCHAINS_STAKED_HF_TIMESTAMP) + if ( !komodo_hardfork_active((uint32_t)chainActive.Tip()->nTime) ) + txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 1; // set to a time close to now else txNew.nLockTime = (uint32_t)chainActive.Tip()->GetMedianTimePast(); From 88ef4f61e00e045a2890a4e4ccb256c245a14740 Mon Sep 17 00:00:00 2001 From: John Jones Date: Fri, 24 Sep 2021 16:23:34 -0500 Subject: [PATCH 3/3] Remove GetLastTipWithLock() --- src/miner.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 709aadaa372..853f110ade6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1681,12 +1681,6 @@ void static BitcoinMiner_noeq() int32_t gotinvalid; extern int32_t getkmdseason(int32_t height); -CBlockIndex * GetLastTipWithLock() -{ - LOCK(cs_main); - return chainActive.Tip(); -} - #ifdef ENABLE_WALLET void static BitcoinMiner(CWallet *pwallet) #else @@ -1776,7 +1770,11 @@ void static BitcoinMiner() // Create new block // unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); - CBlockIndex* pindexPrev = GetLastTipWithLock(); + CBlockIndex* pindexPrev = nullptr; + { + LOCK(cs_main); + pindexPrev = chainActive.Tip(); + } if ( Mining_height != pindexPrev->GetHeight()+1 ) { Mining_height = pindexPrev->GetHeight()+1; @@ -1965,7 +1963,12 @@ void static BitcoinMiner() while ( GetTime() < B.nTime-2 ) { sleep(1); - if ( GetLastTipWithLock()->GetHeight() >= Mining_height ) + CBlockIndex *tip = nullptr; + { + LOCK(cs_main); + tip = chainActive.Tip(); + } + if ( tip->GetHeight() >= Mining_height ) { fprintf(stderr,"new block arrived\n"); return(false); @@ -2123,7 +2126,12 @@ void static BitcoinMiner() fprintf(stderr,"timeout, break\n"); break; } - if ( pindexPrev != GetLastTipWithLock() ) + CBlockIndex *tip = nullptr; + { + LOCK(cs_main); + tip = chainActive.Tip(); + } + if ( pindexPrev != tip ) { break; }