Skip to content

Commit

Permalink
Lock fetching and processing inputs while parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dexX7 committed Jun 3, 2017
1 parent 2cb4ead commit 48e7c19
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/omnicore/omnicore.cpp
Expand Up @@ -666,12 +666,13 @@ static unsigned int nCacheMiss = 0;
/**
* Fetches transaction inputs and adds them to the coins view cache.
*
* Note: cs_tx_cache should be locked, when adding and accessing inputs!
*
* @param tx[in] The transaction to fetch inputs for
* @return True, if all inputs were successfully added to the cache
*/
static bool FillTxInputCache(const CTransaction& tx)
{
LOCK(cs_tx_cache);
static unsigned int nCacheSize = GetArg("-omnitxcache", 500000);

if (view.GetCacheSize() > nCacheSize) {
Expand Down Expand Up @@ -731,6 +732,13 @@ static int parseTransaction(bool bRPConly, const CTransaction& wtx, int nBlock,
PrintToLog("%s(block=%d, %s idx= %d); txid: %s\n", __FUNCTION__, nBlock, DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTime), idx, wtx.GetHash().GetHex());
}

// ### SENDER IDENTIFICATION ###
std::string strSender;
int64_t inAll = 0;

{ // needed to ensure the cache isn't cleared in the meantime when doing parallel queries
LOCK(cs_tx_cache);

// Add previous transaction inputs to the cache
if (!FillTxInputCache(wtx)) {
PrintToLog("%s() ERROR: failed to get inputs for %s\n", __func__, wtx.GetHash().GetHex());
Expand All @@ -739,9 +747,6 @@ static int parseTransaction(bool bRPConly, const CTransaction& wtx, int nBlock,

assert(view.HaveInputs(wtx));

// ### SENDER IDENTIFICATION ###
std::string strSender;

if (omniClass != OMNI_CLASS_C)
{
// OLD LOGIC - collect input amounts and identify sender via "largest input by sum"
Expand Down Expand Up @@ -809,7 +814,10 @@ static int parseTransaction(bool bRPConly, const CTransaction& wtx, int nBlock,
}
}

int64_t inAll = view.GetValueIn(wtx);
inAll = view.GetValueIn(wtx);

} // end of LOCK(cs_tx_cache)

int64_t outAll = wtx.GetValueOut();
int64_t txFee = inAll - outAll; // miner fee

Expand Down

0 comments on commit 48e7c19

Please sign in to comment.