komodo_getblockindex instead of mapblockindex[] to prevent creation of new entry on miss

This commit is contained in:
jl777
2018-11-23 04:17:34 -11:00
parent d39300e3ff
commit 7d54574d4c
7 changed files with 15 additions and 8 deletions

View File

@@ -101,6 +101,7 @@ struct oracleprice_info
extern CWallet* pwalletMain;
#endif
bool GetAddressUnspent(uint160 addressHash, int type,std::vector<std::pair<CAddressUnspentKey,CAddressUnspentValue> > &unspentOutputs);
CBlockIndex *komodo_getblockindex(uint256 hash);
static const uint256 zeroid;
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock);

View File

@@ -436,7 +436,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid)
//fprintf(stderr,"CCduration no hashBlock for txid %s\n",uint256_str(str,txid));
return(0);
}
else if ( (pindex= mapBlockIndex[hashBlock]) == 0 || (txtime= pindex->nTime) == 0 || (txheight= pindex->GetHeight()) <= 0 )
else if ( (pindex= komodo_getblockindex(hashBlock)) == 0 || (txtime= pindex->nTime) == 0 || (txheight= pindex->GetHeight()) <= 0 )
{
fprintf(stderr,"CCduration no txtime %u or txheight.%d %p for txid %s\n",txtime,txheight,pindex,uint256_str(str,txid));
return(0);

View File

@@ -266,7 +266,7 @@ TxProof GetAssetchainProof(uint256 hash)
if (blockHash.IsNull())
throw std::runtime_error("tx still in mempool");
blockIndex = mapBlockIndex[blockHash];
blockIndex = komodo_getblockindex(blockHash);
int h = blockIndex->GetHeight();
// The assumption here is that the first notarisation for a height GTE than
// the transaction block height will contain the corresponding MoM. If there

View File

@@ -510,7 +510,7 @@ int32_t komodo_validate_chain(uint256 srchash,int32_t notarized_height)
static int32_t last_rewind; int32_t rewindtarget; CBlockIndex *pindex; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN];
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
return(0);
if ( IsInitialBlockDownload() == 0 && ((pindex= mapBlockIndex[srchash]) == 0 || pindex->GetHeight() != notarized_height) )
if ( IsInitialBlockDownload() == 0 && ((pindex= komodo_getblockindex(srchash)) == 0 || pindex->GetHeight() != notarized_height) )
{
if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < notarized_height )
rewindtarget = sp->NOTARIZED_HEIGHT - 1;

View File

@@ -578,6 +578,12 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash, int32_t n, char *destaddr)
return(tx.nLockTime);
}
CBlockIndex *komodo_getblockindex(uint256 hash)
{
BlockMap::const_iterator it = mapBlockIndex.find(hash);
return((it != mapBlockIndex.end()) ? it->second : NULL);
}
uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr)
{
CTxDestination address; CBlockIndex *pindex; CTransaction tx; uint256 hashBlock; uint32_t txtime = 0;
@@ -591,7 +597,7 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr)
//fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime);
return(0);
}
if ( (pindex= mapBlockIndex[hashBlock]) != 0 )
if ( (pindex= komodo_getblockindex(hashBlock)) != 0 )
txtime = pindex->nTime;
else txtime = tx.nLockTime;
//fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime);
@@ -1024,7 +1030,7 @@ uint32_t komodo_interest_args(uint32_t *txheighttimep,int32_t *txheightp,uint32_
uint32_t locktime = 0;
if ( n < tx.vout.size() )
{
if ( (pindex= mapBlockIndex[hashBlock]) != 0 )
if ( (pindex= komodo_getblockindex(hashBlock)) != 0 )
{
*valuep = tx.vout[n].nValue;
*txheightp = pindex->GetHeight();

View File

@@ -5065,7 +5065,7 @@ CBlockIndex *komodo_ensure(CBlock *pblock, uint256 hash)
CBlockIndex *oldkomodo_ensure(CBlock *pblock, uint256 hash)
{
CBlockIndex *pindex=0,*previndex=0;
if ( (pindex = mapBlockIndex[hash]) == 0 )
if ( (pindex = komodo_getblockindex(hash)) == 0 )
{
pindex = new CBlockIndex();
if (!pindex)
@@ -7720,7 +7720,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
}
}
/*CBlockIndex *pindex;
if ( komodo_requestedhash != zero && komodo_requestedcount < 16 && (pindex= mapBlockIndex[komodo_requestedhash]) != 0 )
if ( komodo_requestedhash != zero && komodo_requestedcount < 16 && (pindex= komodo_getblockindex(komodo_requestedhash)) != 0 )
{
LogPrint("net","komodo_requestedhash.%d request %s to nodeid.%d\n",komodo_requestedcount,komodo_requestedhash.ToString().c_str(),pto->GetId());
fprintf(stderr,"komodo_requestedhash.%d request %s to nodeid.%d\n",komodo_requestedcount,komodo_requestedhash.ToString().c_str(),pto->GetId());

View File

@@ -5172,7 +5172,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
{
if ( IsMine(*pwalletMain,address) == 0 )
continue;
if ( GetTransaction(out.tx->GetHash(),tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 )
if ( GetTransaction(out.tx->GetHash(),tx,hashBlock,true) != 0 && (pindex= komodo_getblockindex(hashBlock)) != 0 )
{
array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,(CScript)pk);
}