message: wallet: Avoid use of Chain::Lock in CWallet::CreateTransaction
  This is a step toward removing the Chain::Lock class and reducing cs_main
  locking.
  This change only affects behavior in the case where wallet last block processed
  falls behind the chain tip, where it may set a different lock time.
diff: @@ -2716,13 +2716,15 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
  return true;
  }
  -static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, interfaces::Chain::Lock& locked_chain)
  +static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, const uint256& block_hash)
  {
  if (chain.isInitialBlockDownload()) {
  return false;
  }
  constexpr int64_t MAX_ANTI_FEE_SNIPING_TIP_AGE = 8 * 60 * 60; // in seconds
  - if (locked_chain.getBlockTime(*locked_chain.getHeight()) < (GetTime() - MAX_ANTI_FEE_SNIPING_TIP_AGE)) {
  + int64_t block_time;
  + CHECK_NONFATAL(chain.findBlock(block_hash, FoundBlock().time(block_time)));
  + if (block_time < (GetTime() - MAX_ANTI_FEE_SNIPING_TIP_AGE)) {
  return false;
  }
  return true;
  @@ -2732,9 +2734,8 @@ static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, interfaces::Cha
  * Return a height-based locktime for new transactions (uses the height of the
  * current chain tip unless we are not synced with the current chain
  */
  -static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, interfaces::Chain::Lock& locked_chain)
  +static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, const uint256& block_hash, int block_height)
  {
  - uint32_t const height = locked_chain.getHeight().get_value_or(-1);
  uint32_t locktime;
  // Discourage fee sniping.
  //
  @@ -2756,8 +2757,8 @@ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, interface
  // enough, that fee sniping isn't a problem yet, but by implementing a fix
  // now we ensure code won't be written that makes assumptions about
  // nLockTime that preclude a fix later.
  - if (IsCurrentForAntiFeeSniping(chain, locked_chain)) {
  - locktime = height;
  + if (IsCurrentForAntiFeeSniping(chain, block_hash)) {
  + locktime = block_height;
  // Secondly occasionally randomly pick a nLockTime even further back, so
  // that transactions that are delayed after signing for whatever reason,
  @@ -2771,7 +2772,6 @@ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, interface
  // unique "nLockTime fingerprint", set nLockTime to a constant.
  locktime = 0;
  }
  - assert(locktime <= height);
  assert(locktime < LOCKTIME_THRESHOLD);
  return locktime;
  }
  @@ -2832,15 +2832,13 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
  CMutableTransaction txNew;
  txNew.nVersion = gArgs.GetArg("-txversion", CTransaction::CURRENT_VERSION);
  -
  - txNew.nLockTime = GetLocktimeForNewTransaction(chain(), locked_chain);
  -
  CAmount nFeeNeeded;
  int nBytes;
  {
  std::set<CInputCoin> setCoins;
  auto locked_chain = chain().lock();
  LOCK(cs_wallet);
  + txNew.nLockTime = GetLocktimeForNewTransaction(chain(), GetLastBlockHash(), GetLastBlockHeight());
  {
  std::vector<COutput> vAvailableCoins;
  AvailableCoins(*locked_chain, vAvailableCoins, true, &coin_control, txNew.nTime, 1, MAX_MONEY, MAX_MONEY, 0);
  