diff options
author | fanquake <fanquake@gmail.com> | 2022-08-04 16:45:03 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2022-08-04 16:48:14 +0100 |
commit | 36c83b40bd68a993ab6459cb0d5d2c8ce4541147 (patch) | |
tree | 808f8e198b86bcdf2cfb76c2736808f8f19a1fc4 | |
parent | 7312effe6a13364f34a40e5734ffe4943377ab45 (diff) | |
parent | faab8dceb37a944d0763fcca390342111e6a9fcc (diff) |
Merge bitcoin/bitcoin#25023: Remove unused SetTip(nullptr) code
faab8dceb37a944d0763fcca390342111e6a9fcc Remove unused SetTip(nullptr) code (MacroFake)
Pull request description:
Now that this path is no longer used after commit b51e60f91472da5216116626afc032acd5616e85, we can remove it.
Future code should reset `CChain` by simply discarding it and constructing a fresh one.
ACKs for top commit:
ryanofsky:
Code review ACK faab8dceb37a944d0763fcca390342111e6a9fcc. Just moved an assert statement since last review
Tree-SHA512: 7dc273b11133d85d32ca2a69c0c7c07b39cdd338141ef5b51496e7de334a809864d5459eb95535497866c8b1e468aae84ed8f91b543041e6ee20130d5622874e
-rw-r--r-- | src/chain.cpp | 8 | ||||
-rw-r--r-- | src/chain.h | 2 | ||||
-rw-r--r-- | src/test/miner_tests.cpp | 6 | ||||
-rw-r--r-- | src/test/skiplist_tests.cpp | 6 | ||||
-rw-r--r-- | src/validation.cpp | 9 |
5 files changed, 15 insertions, 16 deletions
diff --git a/src/chain.cpp b/src/chain.cpp index 0f898bafd5..446bb216c2 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -18,11 +18,9 @@ std::string CBlockIndex::ToString() const pprev, nHeight, hashMerkleRoot.ToString(), GetBlockHash().ToString()); } -void CChain::SetTip(CBlockIndex *pindex) { - if (pindex == nullptr) { - vChain.clear(); - return; - } +void CChain::SetTip(CBlockIndex& block) +{ + CBlockIndex* pindex = █ vChain.resize(pindex->nHeight + 1); while (pindex && vChain[pindex->nHeight] != pindex) { vChain[pindex->nHeight] = pindex; diff --git a/src/chain.h b/src/chain.h index 627a3dfab2..1c5cd3f1f6 100644 --- a/src/chain.h +++ b/src/chain.h @@ -465,7 +465,7 @@ public: } /** Set/initialize a chain with a given tip. */ - void SetTip(CBlockIndex* pindex); + void SetTip(CBlockIndex& block); /** Return a CBlockLocator that refers to a block in this chain (by default the tip). */ CBlockLocator GetLocator(const CBlockIndex* pindex = nullptr) const; diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index 20d670c1e1..df04bfcc2f 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -325,7 +325,7 @@ void MinerTestingSetup::TestBasicMining(const CChainParams& chainparams, const C next->pprev = prev; next->nHeight = prev->nHeight + 1; next->BuildSkip(); - m_node.chainman->ActiveChain().SetTip(next); + m_node.chainman->ActiveChain().SetTip(*next); } BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey)); // Extend to a 210000-long block chain. @@ -337,7 +337,7 @@ void MinerTestingSetup::TestBasicMining(const CChainParams& chainparams, const C next->pprev = prev; next->nHeight = prev->nHeight + 1; next->BuildSkip(); - m_node.chainman->ActiveChain().SetTip(next); + m_node.chainman->ActiveChain().SetTip(*next); } BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey)); @@ -362,7 +362,7 @@ void MinerTestingSetup::TestBasicMining(const CChainParams& chainparams, const C // Delete the dummy blocks again. while (m_node.chainman->ActiveChain().Tip()->nHeight > nHeight) { CBlockIndex* del = m_node.chainman->ActiveChain().Tip(); - m_node.chainman->ActiveChain().SetTip(del->pprev); + m_node.chainman->ActiveChain().SetTip(*Assert(del->pprev)); m_node.chainman->ActiveChainstate().CoinsTip().SetBestBlock(del->pprev->GetBlockHash()); delete del->phashBlock; delete del; diff --git a/src/test/skiplist_tests.cpp b/src/test/skiplist_tests.cpp index 6dadf09176..3d3fd5d93d 100644 --- a/src/test/skiplist_tests.cpp +++ b/src/test/skiplist_tests.cpp @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE(getlocator_test) // Build a CChain for the main branch. CChain chain; - chain.SetTip(&vBlocksMain.back()); + chain.SetTip(vBlocksMain.back()); // Test 100 random starting points for locators. for (int n=0; n<100; n++) { @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(findearliestatleast_test) // Build a CChain for the main branch. CChain chain; - chain.SetTip(&vBlocksMain.back()); + chain.SetTip(vBlocksMain.back()); // Verify that FindEarliestAtLeast is correct. for (unsigned int i=0; i<10000; ++i) { @@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(findearliestatleast_edge_test) } CChain chain; - chain.SetTip(&blocks.back()); + chain.SetTip(blocks.back()); BOOST_CHECK_EQUAL(chain.FindEarliestAtLeast(50, 0)->nHeight, 0); BOOST_CHECK_EQUAL(chain.FindEarliestAtLeast(100, 0)->nHeight, 0); diff --git a/src/validation.cpp b/src/validation.cpp index c924bb3c34..d30333f710 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2583,6 +2583,7 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr CBlockIndex *pindexDelete = m_chain.Tip(); assert(pindexDelete); + assert(pindexDelete->pprev); // Read block from disk. std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>(); CBlock& block = *pblock; @@ -2630,7 +2631,7 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr } } - m_chain.SetTip(pindexDelete->pprev); + m_chain.SetTip(*pindexDelete->pprev); UpdateTip(pindexDelete->pprev); // Let wallets know transactions went from 1-confirmed to @@ -2744,7 +2745,7 @@ bool CChainState::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew disconnectpool.removeForBlock(blockConnecting.vtx); } // Update m_chain & related variables. - m_chain.SetTip(pindexNew); + m_chain.SetTip(*pindexNew); UpdateTip(pindexNew); int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1; @@ -3892,7 +3893,7 @@ bool CChainState::LoadChainTip() if (!pindex) { return false; } - m_chain.SetTip(pindex); + m_chain.SetTip(*pindex); PruneBlockIndexCandidates(); tip = m_chain.Tip(); @@ -4969,7 +4970,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot( return false; } - snapshot_chainstate.m_chain.SetTip(snapshot_start_block); + snapshot_chainstate.m_chain.SetTip(*snapshot_start_block); // The remainder of this function requires modifying data protected by cs_main. LOCK(::cs_main); |