diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-11-23 18:03:11 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-12-02 15:59:53 +0100 |
commit | fa3942fc4c66d7624bd3578d1e7f4a6a7721c11a (patch) | |
tree | d91444c325bbf2f2d6390e8aa6ea7752d3d384e1 /src/validation.cpp | |
parent | 26a1147ce56083d7aa820ac115c16b01e47d911c (diff) |
Remove GetSpendHeight
It is unclear what the goal of the helper is, as the caller already
knows the spend height before calling the helper.
Also, in case the coins view is corrupted, LookupBlockIndex will return
nullptr. Dereferencing a nullptr is UB.
Fix both issues by removing it. Also, add a sanity check, which aborts
if the coins view is corrupted.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index 6ed5e7a548..0595cd8f4b 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -723,6 +723,8 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws) // to coins_to_uncache) m_view.SetBackend(m_dummy); + assert(m_active_chainstate.m_blockman.LookupBlockIndex(m_view.GetBestBlock()) == m_active_chainstate.m_chain.Tip()); + // Only accept BIP68 sequence locked transactions that can be mined in the next // block; we don't want our mempool filled up with transactions that can't // be mined yet. @@ -731,7 +733,8 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws) if (!CheckSequenceLocks(m_active_chainstate.m_chain.Tip(), m_view, tx, STANDARD_LOCKTIME_VERIFY_FLAGS, &lp)) return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-BIP68-final"); - if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_blockman.GetSpendHeight(m_view), ws.m_base_fees)) { + // The mempool holds txs for the next block, so pass height+1 to CheckTxInputs + if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_chain.Height() + 1, ws.m_base_fees)) { return false; // state filled in by CheckTxInputs } @@ -1311,14 +1314,6 @@ bool CScriptCheck::operator()() { return VerifyScript(scriptSig, m_tx_out.scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, m_tx_out.nValue, cacheStore, *txdata), &error); } -int BlockManager::GetSpendHeight(const CCoinsViewCache& inputs) -{ - AssertLockHeld(cs_main); - CBlockIndex* pindexPrev = LookupBlockIndex(inputs.GetBestBlock()); - return pindexPrev->nHeight + 1; -} - - static CuckooCache::cache<uint256, SignatureCacheHasher> g_scriptExecutionCache; static CSHA256 g_scriptExecutionCacheHasher; |