Skip to content

Commit e4b95ee

Browse files
committed
validation: Move GetSpendHeight to BlockManager
[META] This commit should be followed up by removing the comments and assertions meant only to show that the change is correct. GetSpendHeight only acts on BlockManager.
1 parent b026e31 commit e4b95ee

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/txmempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
626626
uint64_t innerUsage = 0;
627627

628628
CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(pcoins));
629-
const int64_t spendheight = GetSpendHeight(mempoolDuplicate);
629+
const int64_t spendheight = g_chainman.m_blockman.GetSpendHeight(mempoolDuplicate);
630630

631631
std::list<const CTxMemPoolEntry*> waitingOnDependants;
632632
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {

src/validation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
684684
return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-BIP68-final");
685685

686686
CAmount nFees = 0;
687-
if (!Consensus::CheckTxInputs(tx, state, m_view, GetSpendHeight(m_view), nFees)) {
687+
if (!Consensus::CheckTxInputs(tx, state, m_view, g_chainman.m_blockman.GetSpendHeight(m_view), nFees)) {
688688
return false; // state filled in by CheckTxInputs
689689
}
690690

@@ -1412,10 +1412,11 @@ bool CScriptCheck::operator()() {
14121412
return VerifyScript(scriptSig, m_tx_out.scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, m_tx_out.nValue, cacheStore, *txdata), &error);
14131413
}
14141414

1415-
int GetSpendHeight(const CCoinsViewCache& inputs)
1415+
int BlockManager::GetSpendHeight(const CCoinsViewCache& inputs)
14161416
{
1417-
LOCK(cs_main);
1418-
CBlockIndex* pindexPrev = g_chainman.m_blockman.LookupBlockIndex(inputs.GetBestBlock());
1417+
AssertLockHeld(cs_main);
1418+
assert(std::addressof(g_chainman.m_blockman) == std::addressof(*this));
1419+
CBlockIndex* pindexPrev = LookupBlockIndex(inputs.GetBestBlock());
14191420
return pindexPrev->nHeight + 1;
14201421
}
14211422

src/validation.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,13 @@ class BlockManager
433433
/** Find the last common block between the parameter chain and a locator. */
434434
CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
435435

436+
/**
437+
* Return the spend height, which is one more than the inputs.GetBestBlock().
438+
* While checking, GetBestBlock() refers to the parent block. (protected by cs_main)
439+
* This is also true for mempool checks.
440+
*/
441+
int GetSpendHeight(const CCoinsViewCache& inputs) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
442+
436443
~BlockManager() {
437444
Unload();
438445
}
@@ -945,13 +952,6 @@ CChain& ChainActive();
945952
/** Global variable that points to the active block tree (protected by cs_main) */
946953
extern std::unique_ptr<CBlockTreeDB> pblocktree;
947954

948-
/**
949-
* Return the spend height, which is one more than the inputs.GetBestBlock().
950-
* While checking, GetBestBlock() refers to the parent block. (protected by cs_main)
951-
* This is also true for mempool checks.
952-
*/
953-
int GetSpendHeight(const CCoinsViewCache& inputs);
954-
955955
extern VersionBitsCache versionbitscache;
956956

957957
/**

0 commit comments

Comments
 (0)