message: Need to maintain cs_orphancache lock for xthins and thinblocks
  We have to maintain the lock as well as keep the correct locking
  order for the duration of the creation of xthins or thinblocks
diff: @@ -70,6 +70,8 @@ bool CThinBlock::process(CNode* pfrom, int nSizeThinBlock, string strCommand)
  BOOST_FOREACH(CTransaction tx, vMissingTx)
  mapMissingTx[tx.GetHash()] = tx;
  + {
  + LOCK(cs_orphancache);
  // We don't have to keep the lock on mempool.cs here to do mempool.queryHashes
  // but we take the lock anyway so we don't have to re-lock again later.
  LOCK2(mempool.cs, cs_xval);
  @@ -105,6 +107,7 @@ bool CThinBlock::process(CNode* pfrom, int nSizeThinBlock, string strCommand)
  }
  pfrom->thinBlockWaitingForTxns = missingCount;
  LogPrint("thin", "Thinblock %s waiting for: %d, unnecessary: %d, txs: %d full: %d\n", pfrom->thinBlock.GetHash().ToString(), pfrom->thinBlockWaitingForTxns, unnecessaryCount, pfrom->thinBlock.vtx.size(), mapMissingTx.size());
  + } // end lock cs_orphancache, mempool.cs, cs_xval
  if (pfrom->thinBlockWaitingForTxns == 0) {
  // We have all the transactions now that are in this block: try to reassemble and process.
  @@ -259,8 +262,8 @@ bool CXThinBlock::process(CNode* pfrom, int nSizeThinBlock, string strCommand)
  map<uint64_t, uint256> mapPartialTxHash;
  vector<uint256> memPoolHashes;
  - // Do the orphans first before taking the mempool.cs lock, so that we maintain correct locking order.
  {
  + // Do the orphans first before taking the mempool.cs lock, so that we maintain correct locking order.
  LOCK(cs_orphancache);
  for (map<uint256, COrphanTx>::iterator mi = mapOrphanTransactions.begin(); mi != mapOrphanTransactions.end(); ++mi) {
  uint64_t cheapHash = (*mi).first.GetCheapHash();
  @@ -268,8 +271,7 @@ bool CXThinBlock::process(CNode* pfrom, int nSizeThinBlock, string strCommand)
  collision = true;
  mapPartialTxHash[cheapHash] = (*mi).first;
  }
  - }
  - {
  +
  // We don't have to keep the lock on mempool.cs here to do mempool.queryHashes
  // but we take the lock anyway so we don't have to re-lock again later.
  LOCK2(mempool.cs, cs_xval);
  @@ -328,7 +330,7 @@ bool CXThinBlock::process(CNode* pfrom, int nSizeThinBlock, string strCommand)
  pfrom->thinBlock.vtx.push_back(tx);
  }
  }
  - } // End locking mempool.cs and cs_xval
  + } // End locking cs_orphancache, mempool.cs and cs_xval
  // There is a remote possiblity of a Tx hash collision therefore if it occurs we re-request a normal
  // thinblock which has the full Tx hash data rather than just the truncated hash.
  