mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 19:37:27 -03:00
validation: assumeutxo: swap m_mempool on snapshot activation
Otherwise we will not receive transactions during background sync until restart.
This commit is contained in:
parent
7fcd21544a
commit
9511fb3616
3 changed files with 19 additions and 13 deletions
|
@ -38,8 +38,6 @@ BOOST_FIXTURE_TEST_SUITE(validation_chainstatemanager_tests, TestingSetup)
|
|||
BOOST_FIXTURE_TEST_CASE(chainstatemanager, TestChain100Setup)
|
||||
{
|
||||
ChainstateManager& manager = *m_node.chainman;
|
||||
CTxMemPool& mempool = *m_node.mempool;
|
||||
|
||||
std::vector<Chainstate*> chainstates;
|
||||
|
||||
BOOST_CHECK(!manager.SnapshotBlockhash().has_value());
|
||||
|
@ -69,8 +67,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager, TestChain100Setup)
|
|||
// Create a snapshot-based chainstate.
|
||||
//
|
||||
const uint256 snapshot_blockhash = active_tip->GetBlockHash();
|
||||
Chainstate& c2 = WITH_LOCK(::cs_main, return manager.ActivateExistingSnapshot(
|
||||
&mempool, snapshot_blockhash));
|
||||
Chainstate& c2 = WITH_LOCK(::cs_main, return manager.ActivateExistingSnapshot(snapshot_blockhash));
|
||||
chainstates.push_back(&c2);
|
||||
c2.InitCoinsDB(
|
||||
/*cache_size_bytes=*/1 << 23, /*in_memory=*/true, /*should_wipe=*/false);
|
||||
|
@ -113,7 +110,6 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager, TestChain100Setup)
|
|||
BOOST_FIXTURE_TEST_CASE(chainstatemanager_rebalance_caches, TestChain100Setup)
|
||||
{
|
||||
ChainstateManager& manager = *m_node.chainman;
|
||||
CTxMemPool& mempool = *m_node.mempool;
|
||||
|
||||
size_t max_cache = 10000;
|
||||
manager.m_total_coinsdb_cache = max_cache;
|
||||
|
@ -137,7 +133,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_rebalance_caches, TestChain100Setup)
|
|||
// Create a snapshot-based chainstate.
|
||||
//
|
||||
CBlockIndex* snapshot_base{WITH_LOCK(manager.GetMutex(), return manager.ActiveChain()[manager.ActiveChain().Height() / 2])};
|
||||
Chainstate& c2 = WITH_LOCK(cs_main, return manager.ActivateExistingSnapshot(&mempool, *snapshot_base->phashBlock));
|
||||
Chainstate& c2 = WITH_LOCK(cs_main, return manager.ActivateExistingSnapshot(*snapshot_base->phashBlock));
|
||||
chainstates.push_back(&c2);
|
||||
c2.InitCoinsDB(
|
||||
/*cache_size_bytes=*/1 << 23, /*in_memory=*/true, /*should_wipe=*/false);
|
||||
|
@ -423,7 +419,6 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, SnapshotTestSetup)
|
|||
BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup)
|
||||
{
|
||||
ChainstateManager& chainman = *Assert(m_node.chainman);
|
||||
CTxMemPool& mempool = *m_node.mempool;
|
||||
Chainstate& cs1 = chainman.ActiveChainstate();
|
||||
|
||||
int num_indexes{0};
|
||||
|
@ -493,7 +488,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup)
|
|||
|
||||
// Note: cs2's tip is not set when ActivateExistingSnapshot is called.
|
||||
Chainstate& cs2 = WITH_LOCK(::cs_main,
|
||||
return chainman.ActivateExistingSnapshot(&mempool, *assumed_base->phashBlock));
|
||||
return chainman.ActivateExistingSnapshot(*assumed_base->phashBlock));
|
||||
|
||||
// Set tip of the fully validated chain to be the validated tip
|
||||
cs1.m_chain.SetTip(*validated_tip);
|
||||
|
|
|
@ -5268,6 +5268,12 @@ bool ChainstateManager::ActivateSnapshot(
|
|||
const bool chaintip_loaded = m_snapshot_chainstate->LoadChainTip();
|
||||
assert(chaintip_loaded);
|
||||
|
||||
// Transfer possession of the mempool to the snapshot chianstate.
|
||||
// Mempool is empty at this point because we're still in IBD.
|
||||
Assert(m_active_chainstate->m_mempool->size() == 0);
|
||||
Assert(!m_snapshot_chainstate->m_mempool);
|
||||
m_snapshot_chainstate->m_mempool = m_active_chainstate->m_mempool;
|
||||
m_active_chainstate->m_mempool = nullptr;
|
||||
m_active_chainstate = m_snapshot_chainstate.get();
|
||||
m_blockman.m_snapshot_height = this->GetSnapshotBaseHeight();
|
||||
|
||||
|
@ -5747,16 +5753,22 @@ bool ChainstateManager::DetectSnapshotChainstate(CTxMemPool* mempool)
|
|||
LogPrintf("[snapshot] detected active snapshot chainstate (%s) - loading\n",
|
||||
fs::PathToString(*path));
|
||||
|
||||
this->ActivateExistingSnapshot(mempool, *base_blockhash);
|
||||
this->ActivateExistingSnapshot(*base_blockhash);
|
||||
return true;
|
||||
}
|
||||
|
||||
Chainstate& ChainstateManager::ActivateExistingSnapshot(CTxMemPool* mempool, uint256 base_blockhash)
|
||||
Chainstate& ChainstateManager::ActivateExistingSnapshot(uint256 base_blockhash)
|
||||
{
|
||||
assert(!m_snapshot_chainstate);
|
||||
m_snapshot_chainstate =
|
||||
std::make_unique<Chainstate>(mempool, m_blockman, *this, base_blockhash);
|
||||
std::make_unique<Chainstate>(nullptr, m_blockman, *this, base_blockhash);
|
||||
LogPrintf("[snapshot] switching active chainstate to %s\n", m_snapshot_chainstate->ToString());
|
||||
|
||||
// Mempool is empty at this point because we're still in IBD.
|
||||
Assert(m_active_chainstate->m_mempool->size() == 0);
|
||||
Assert(!m_snapshot_chainstate->m_mempool);
|
||||
m_snapshot_chainstate->m_mempool = m_active_chainstate->m_mempool;
|
||||
m_active_chainstate->m_mempool = nullptr;
|
||||
m_active_chainstate = m_snapshot_chainstate.get();
|
||||
return *m_snapshot_chainstate;
|
||||
}
|
||||
|
|
|
@ -1213,8 +1213,7 @@ public:
|
|||
|
||||
//! Switch the active chainstate to one based on a UTXO snapshot that was loaded
|
||||
//! previously.
|
||||
Chainstate& ActivateExistingSnapshot(CTxMemPool* mempool, uint256 base_blockhash)
|
||||
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
Chainstate& ActivateExistingSnapshot(uint256 base_blockhash) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
|
||||
//! If we have validated a snapshot chain during this runtime, copy its
|
||||
//! chainstate directory over to the main `chainstate` location, completing
|
||||
|
|
Loading…
Reference in a new issue