mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 18:53:23 -03:00
refactor: remove unused assumeutxo methods
After feedback from Russ, I realized that there are some extraneous assumeutxo methods that are not necessary and probably just overly confusing. These include - `Validated*()` - `IsBackgroundIBD()` and they can be removed.
This commit is contained in:
parent
9f6bb53935
commit
ac4051d891
3 changed files with 10 additions and 59 deletions
|
@ -44,7 +44,6 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||||
|
|
||||||
BOOST_CHECK(!manager.IsSnapshotActive());
|
BOOST_CHECK(!manager.IsSnapshotActive());
|
||||||
BOOST_CHECK(!manager.IsSnapshotValidated());
|
BOOST_CHECK(!manager.IsSnapshotValidated());
|
||||||
BOOST_CHECK(!manager.IsBackgroundIBD(&c1));
|
|
||||||
auto all = manager.GetAll();
|
auto all = manager.GetAll();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(all.begin(), all.end(), chainstates.begin(), chainstates.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(all.begin(), all.end(), chainstates.begin(), chainstates.end());
|
||||||
|
|
||||||
|
@ -57,9 +56,6 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||||
auto exp_tip = c1.m_chain.Tip();
|
auto exp_tip = c1.m_chain.Tip();
|
||||||
BOOST_CHECK_EQUAL(active_tip, exp_tip);
|
BOOST_CHECK_EQUAL(active_tip, exp_tip);
|
||||||
|
|
||||||
auto& validated_cs = manager.ValidatedChainstate();
|
|
||||||
BOOST_CHECK_EQUAL(&validated_cs, &c1);
|
|
||||||
|
|
||||||
BOOST_CHECK(!manager.SnapshotBlockhash().has_value());
|
BOOST_CHECK(!manager.SnapshotBlockhash().has_value());
|
||||||
|
|
||||||
// Create a snapshot-based chainstate.
|
// Create a snapshot-based chainstate.
|
||||||
|
@ -81,8 +77,8 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||||
|
|
||||||
BOOST_CHECK(manager.IsSnapshotActive());
|
BOOST_CHECK(manager.IsSnapshotActive());
|
||||||
BOOST_CHECK(!manager.IsSnapshotValidated());
|
BOOST_CHECK(!manager.IsSnapshotValidated());
|
||||||
BOOST_CHECK(manager.IsBackgroundIBD(&c1));
|
BOOST_CHECK_EQUAL(&c2, &manager.ActiveChainstate());
|
||||||
BOOST_CHECK(!manager.IsBackgroundIBD(&c2));
|
BOOST_CHECK(&c1 != &manager.ActiveChainstate());
|
||||||
auto all2 = manager.GetAll();
|
auto all2 = manager.GetAll();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(all2.begin(), all2.end(), chainstates.begin(), chainstates.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(all2.begin(), all2.end(), chainstates.begin(), chainstates.end());
|
||||||
|
|
||||||
|
@ -99,16 +95,6 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||||
// CCoinsViewCache instances.
|
// CCoinsViewCache instances.
|
||||||
BOOST_CHECK(exp_tip != exp_tip2);
|
BOOST_CHECK(exp_tip != exp_tip2);
|
||||||
|
|
||||||
auto& validated_cs2 = manager.ValidatedChainstate();
|
|
||||||
BOOST_CHECK_EQUAL(&validated_cs2, &c1);
|
|
||||||
|
|
||||||
auto& validated_chain = manager.ValidatedChain();
|
|
||||||
BOOST_CHECK_EQUAL(&validated_chain, &c1.m_chain);
|
|
||||||
|
|
||||||
auto validated_tip = manager.ValidatedTip();
|
|
||||||
exp_tip = c1.m_chain.Tip();
|
|
||||||
BOOST_CHECK_EQUAL(validated_tip, exp_tip);
|
|
||||||
|
|
||||||
// Let scheduler events finish running to avoid accessing memory that is going to be unloaded
|
// Let scheduler events finish running to avoid accessing memory that is going to be unloaded
|
||||||
SyncWithValidationInterfaceQueue();
|
SyncWithValidationInterfaceQueue();
|
||||||
|
|
||||||
|
@ -321,27 +307,27 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup)
|
||||||
{
|
{
|
||||||
LOCK(::cs_main);
|
LOCK(::cs_main);
|
||||||
size_t coins_in_active{0};
|
size_t coins_in_active{0};
|
||||||
size_t coins_in_ibd{0};
|
size_t coins_in_background{0};
|
||||||
size_t coins_missing_ibd{0};
|
size_t coins_missing_from_background{0};
|
||||||
|
|
||||||
for (CChainState* chainstate : chainman.GetAll()) {
|
for (CChainState* chainstate : chainman.GetAll()) {
|
||||||
BOOST_TEST_MESSAGE("Checking coins in " << chainstate->ToString());
|
BOOST_TEST_MESSAGE("Checking coins in " << chainstate->ToString());
|
||||||
CCoinsViewCache& coinscache = chainstate->CoinsTip();
|
CCoinsViewCache& coinscache = chainstate->CoinsTip();
|
||||||
bool is_ibd = chainman.IsBackgroundIBD(chainstate);
|
bool is_background = chainstate != &chainman.ActiveChainstate();
|
||||||
|
|
||||||
for (CTransactionRef& txn : m_coinbase_txns) {
|
for (CTransactionRef& txn : m_coinbase_txns) {
|
||||||
COutPoint op{txn->GetHash(), 0};
|
COutPoint op{txn->GetHash(), 0};
|
||||||
if (coinscache.HaveCoin(op)) {
|
if (coinscache.HaveCoin(op)) {
|
||||||
(is_ibd ? coins_in_ibd : coins_in_active)++;
|
(is_background ? coins_in_background : coins_in_active)++;
|
||||||
} else if (is_ibd) {
|
} else if (is_background) {
|
||||||
coins_missing_ibd++;
|
coins_missing_from_background++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(coins_in_active, initial_total_coins + new_coins);
|
BOOST_CHECK_EQUAL(coins_in_active, initial_total_coins + new_coins);
|
||||||
BOOST_CHECK_EQUAL(coins_in_ibd, initial_total_coins);
|
BOOST_CHECK_EQUAL(coins_in_background, initial_total_coins);
|
||||||
BOOST_CHECK_EQUAL(coins_missing_ibd, new_coins);
|
BOOST_CHECK_EQUAL(coins_missing_from_background, new_coins);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Snapshot should refuse to load after one has already loaded.
|
// Snapshot should refuse to load after one has already loaded.
|
||||||
|
|
|
@ -5007,22 +5007,6 @@ bool ChainstateManager::IsSnapshotActive() const
|
||||||
return m_snapshot_chainstate && m_active_chainstate == m_snapshot_chainstate.get();
|
return m_snapshot_chainstate && m_active_chainstate == m_snapshot_chainstate.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
CChainState& ChainstateManager::ValidatedChainstate() const
|
|
||||||
{
|
|
||||||
LOCK(::cs_main);
|
|
||||||
if (m_snapshot_chainstate && IsSnapshotValidated()) {
|
|
||||||
return *m_snapshot_chainstate.get();
|
|
||||||
}
|
|
||||||
assert(m_ibd_chainstate);
|
|
||||||
return *m_ibd_chainstate.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ChainstateManager::IsBackgroundIBD(CChainState* chainstate) const
|
|
||||||
{
|
|
||||||
LOCK(::cs_main);
|
|
||||||
return (m_snapshot_chainstate && chainstate == m_ibd_chainstate.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChainstateManager::Unload()
|
void ChainstateManager::Unload()
|
||||||
{
|
{
|
||||||
for (CChainState* chainstate : this->GetAll()) {
|
for (CChainState* chainstate : this->GetAll()) {
|
||||||
|
|
|
@ -862,12 +862,6 @@ private:
|
||||||
* *Background IBD chainstate*: an IBD chainstate for which the
|
* *Background IBD chainstate*: an IBD chainstate for which the
|
||||||
* IBD process is happening in the background while use of the
|
* IBD process is happening in the background while use of the
|
||||||
* active (snapshot) chainstate allows the rest of the system to function.
|
* active (snapshot) chainstate allows the rest of the system to function.
|
||||||
*
|
|
||||||
* *Validated chainstate*: the most-work chainstate which has been validated
|
|
||||||
* locally via initial block download. This will be the snapshot chainstate
|
|
||||||
* if a snapshot was loaded and all blocks up to the snapshot starting point
|
|
||||||
* have been downloaded and validated (via background validation), otherwise
|
|
||||||
* it will be the IBD chainstate.
|
|
||||||
*/
|
*/
|
||||||
class ChainstateManager
|
class ChainstateManager
|
||||||
{
|
{
|
||||||
|
@ -986,19 +980,6 @@ public:
|
||||||
//! Is there a snapshot in use and has it been fully validated?
|
//! Is there a snapshot in use and has it been fully validated?
|
||||||
bool IsSnapshotValidated() const { return m_snapshot_validated; }
|
bool IsSnapshotValidated() const { return m_snapshot_validated; }
|
||||||
|
|
||||||
//! @returns true if this chainstate is being used to validate an active
|
|
||||||
//! snapshot in the background.
|
|
||||||
bool IsBackgroundIBD(CChainState* chainstate) const;
|
|
||||||
|
|
||||||
//! Return the most-work chainstate that has been fully validated.
|
|
||||||
//!
|
|
||||||
//! During background validation of a snapshot, this is the IBD chain. After
|
|
||||||
//! background validation has completed, this is the snapshot chain.
|
|
||||||
CChainState& ValidatedChainstate() const;
|
|
||||||
|
|
||||||
CChain& ValidatedChain() const { return ValidatedChainstate().m_chain; }
|
|
||||||
CBlockIndex* ValidatedTip() const { return ValidatedChain().Tip(); }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process an incoming block. This only returns after the best known valid
|
* Process an incoming block. This only returns after the best known valid
|
||||||
* block is made active. Note that it does not, however, guarantee that the
|
* block is made active. Note that it does not, however, guarantee that the
|
||||||
|
|
Loading…
Add table
Reference in a new issue