message: fix lock ordering issue between cs_utxo and cs_blockvalidationthread
diff: @@ -2222,11 +2222,20 @@ bool ConnectBlockDependencyOrdering(const CBlock &block,
  // be in ConnectBlock because they require the UTXO set
  prevheights.resize(tx.vin.size());
  {
  + bool abort = false;
  for (size_t j = 0; j < tx.vin.size(); j++)
  {
  CoinAccessor coin(view, tx.vin[j].prevout);
  // isSpend is true for empty coin object (coinEmpty)
  if (coin->IsSpent())
  + {
  + abort = true;
  + break;
  + }
  + prevheights[j] = coin->nHeight;
  + nFees = nFees + coin->out.nValue;
  + }
  + if (abort)
  {
  // If we were validating at the same time as another block and the other block wins the
  // validation race and updates the UTXO first, then we may end up here with missing inputs.
  @@ -2240,9 +2249,6 @@ bool ConnectBlockDependencyOrdering(const CBlock &block,
  block.GetHash().ToString(), i, tx.GetHash().ToString()),
  REJECT_INVALID, "bad-txns-inputs-missingorspent");
  }
  - prevheights[j] = coin->nHeight;
  - nFees = nFees + coin->out.nValue;
  - }
  }
  nFees = nFees - tx.GetValueOut();
  @@ -2454,11 +2460,20 @@ bool ConnectBlockCanonicalOrdering(const CBlock &block,
  // be in ConnectBlock because they require the UTXO set
  prevheights.resize(tx.vin.size());
  {
  + bool abort = false;
  for (size_t j = 0; j < tx.vin.size(); j++)
  {
  CoinAccessor coin(view, tx.vin[j].prevout);
  // isSpend is true for empty coin object (coinEmpty)
  if (coin->IsSpent())
  + {
  + abort = true;
  + break;
  + }
  + prevheights[j] = coin->nHeight;
  + nFees = nFees + coin->out.nValue;
  + }
  + if (abort)
  {
  // If we were validating at the same time as another block and the other block wins the
  // validation race and updates the UTXO first, then we may end up here with missing inputs.
  @@ -2472,9 +2487,6 @@ bool ConnectBlockCanonicalOrdering(const CBlock &block,
  block.GetHash().ToString(), i, tx.GetHash().ToString()),
  REJECT_INVALID, "bad-txns-inputs-missingorspent");
  }
  - prevheights[j] = coin->nHeight;
  - nFees = nFees + coin->out.nValue;
  - }
  }
  nFees = nFees - tx.GetValueOut();
  