Skip to content

Commit 345c818

Browse files
committed
Merge bitcoin/bitcoin#23630: Remove GetSpendHeight
fa3942f Remove GetSpendHeight (MarcoFalke) Pull request description: 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. ACKs for top commit: laanwj: Code review ACK fa3942f ryanofsky: Code review ACK fa3942f. I'm not aware of cases where coins GetBestBlock could be different from active chain tip, and asset seems sufficient to guarantee PR doesn't change behavior if that doesn't happen. Tree-SHA512: 29f65d72e116ec5a4509e0947ceeaa5bb6b7dfd5d174d3c7945cb15fa266d590c4f8b48e6385de74ef7d7c84ebd2255de902ad9c87c24955348a91b12e5bffd5
2 parents 8b1de78 + fa3942f commit 345c818

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

src/validation.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,8 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
723723
// to coins_to_uncache)
724724
m_view.SetBackend(m_dummy);
725725

726+
assert(m_active_chainstate.m_blockman.LookupBlockIndex(m_view.GetBestBlock()) == m_active_chainstate.m_chain.Tip());
727+
726728
// Only accept BIP68 sequence locked transactions that can be mined in the next
727729
// block; we don't want our mempool filled up with transactions that can't
728730
// be mined yet.
@@ -731,7 +733,8 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
731733
if (!CheckSequenceLocks(m_active_chainstate.m_chain.Tip(), m_view, tx, STANDARD_LOCKTIME_VERIFY_FLAGS, &lp))
732734
return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-BIP68-final");
733735

734-
if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_blockman.GetSpendHeight(m_view), ws.m_base_fees)) {
736+
// The mempool holds txs for the next block, so pass height+1 to CheckTxInputs
737+
if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_chain.Height() + 1, ws.m_base_fees)) {
735738
return false; // state filled in by CheckTxInputs
736739
}
737740

@@ -1311,14 +1314,6 @@ bool CScriptCheck::operator()() {
13111314
return VerifyScript(scriptSig, m_tx_out.scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, m_tx_out.nValue, cacheStore, *txdata), &error);
13121315
}
13131316

1314-
int BlockManager::GetSpendHeight(const CCoinsViewCache& inputs)
1315-
{
1316-
AssertLockHeld(cs_main);
1317-
CBlockIndex* pindexPrev = LookupBlockIndex(inputs.GetBestBlock());
1318-
return pindexPrev->nHeight + 1;
1319-
}
1320-
1321-
13221317
static CuckooCache::cache<uint256, SignatureCacheHasher> g_scriptExecutionCache;
13231318
static CSHA256 g_scriptExecutionCacheHasher;
13241319

src/validation.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,6 @@ class BlockManager
478478
//! Returns last CBlockIndex* that is a checkpoint
479479
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
480480

481-
/**
482-
* Return the spend height, which is one more than the inputs.GetBestBlock().
483-
* While checking, GetBestBlock() refers to the parent block. (protected by cs_main)
484-
* This is also true for mempool checks.
485-
*/
486-
int GetSpendHeight(const CCoinsViewCache& inputs) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
487-
488481
~BlockManager() {
489482
Unload();
490483
}

0 commit comments

Comments
 (0)