add Chainstate::HasCoinsViews()

Used in subsequent commits. Also cleans up asserts in
coins_views-related convenience methods to be more exact.
This commit is contained in:
James O'Beirne
2022-02-02 14:44:50 -05:00
parent c29f26b47b
commit 637a90b973

View File

@@ -553,15 +553,15 @@ public:
CCoinsViewCache& CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(::cs_main) CCoinsViewCache& CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
{ {
AssertLockHeld(::cs_main); AssertLockHeld(::cs_main);
assert(m_coins_views->m_cacheview); Assert(m_coins_views);
return *m_coins_views->m_cacheview.get(); return *Assert(m_coins_views->m_cacheview);
} }
//! @returns A reference to the on-disk UTXO set database. //! @returns A reference to the on-disk UTXO set database.
CCoinsViewDB& CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main) CCoinsViewDB& CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
{ {
AssertLockHeld(::cs_main); AssertLockHeld(::cs_main);
return m_coins_views->m_dbview; return Assert(m_coins_views)->m_dbview;
} }
//! @returns A pointer to the mempool. //! @returns A pointer to the mempool.
@@ -575,12 +575,15 @@ public:
CCoinsViewErrorCatcher& CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(::cs_main) CCoinsViewErrorCatcher& CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
{ {
AssertLockHeld(::cs_main); AssertLockHeld(::cs_main);
return m_coins_views->m_catcherview; return Assert(m_coins_views)->m_catcherview;
} }
//! Destructs all objects related to accessing the UTXO set. //! Destructs all objects related to accessing the UTXO set.
void ResetCoinsViews() { m_coins_views.reset(); } void ResetCoinsViews() { m_coins_views.reset(); }
//! Does this chainstate have a UTXO set attached?
bool HasCoinsViews() const { return (bool)m_coins_views; }
//! The cache size of the on-disk coins view. //! The cache size of the on-disk coins view.
size_t m_coinsdb_cache_size_bytes{0}; size_t m_coinsdb_cache_size_bytes{0};