Skip to content

Commit faab8dc

Browse files
author
MacroFake
committed
Remove unused SetTip(nullptr) code
1 parent 816ca01 commit faab8dc

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

src/chain.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ std::string CBlockIndex::ToString() const
1818
pprev, nHeight, hashMerkleRoot.ToString(), GetBlockHash().ToString());
1919
}
2020

21-
void CChain::SetTip(CBlockIndex *pindex) {
22-
if (pindex == nullptr) {
23-
vChain.clear();
24-
return;
25-
}
21+
void CChain::SetTip(CBlockIndex& block)
22+
{
23+
CBlockIndex* pindex = █
2624
vChain.resize(pindex->nHeight + 1);
2725
while (pindex && vChain[pindex->nHeight] != pindex) {
2826
vChain[pindex->nHeight] = pindex;

src/chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class CChain
465465
}
466466

467467
/** Set/initialize a chain with a given tip. */
468-
void SetTip(CBlockIndex* pindex);
468+
void SetTip(CBlockIndex& block);
469469

470470
/** Return a CBlockLocator that refers to a block in this chain (by default the tip). */
471471
CBlockLocator GetLocator(const CBlockIndex* pindex = nullptr) const;

src/test/miner_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void MinerTestingSetup::TestBasicMining(const CChainParams& chainparams, const C
325325
next->pprev = prev;
326326
next->nHeight = prev->nHeight + 1;
327327
next->BuildSkip();
328-
m_node.chainman->ActiveChain().SetTip(next);
328+
m_node.chainman->ActiveChain().SetTip(*next);
329329
}
330330
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
331331
// Extend to a 210000-long block chain.
@@ -337,7 +337,7 @@ void MinerTestingSetup::TestBasicMining(const CChainParams& chainparams, const C
337337
next->pprev = prev;
338338
next->nHeight = prev->nHeight + 1;
339339
next->BuildSkip();
340-
m_node.chainman->ActiveChain().SetTip(next);
340+
m_node.chainman->ActiveChain().SetTip(*next);
341341
}
342342
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
343343

@@ -362,7 +362,7 @@ void MinerTestingSetup::TestBasicMining(const CChainParams& chainparams, const C
362362
// Delete the dummy blocks again.
363363
while (m_node.chainman->ActiveChain().Tip()->nHeight > nHeight) {
364364
CBlockIndex* del = m_node.chainman->ActiveChain().Tip();
365-
m_node.chainman->ActiveChain().SetTip(del->pprev);
365+
m_node.chainman->ActiveChain().SetTip(*Assert(del->pprev));
366366
m_node.chainman->ActiveChainstate().CoinsTip().SetBestBlock(del->pprev->GetBlockHash());
367367
delete del->phashBlock;
368368
delete del;

src/test/skiplist_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
7272

7373
// Build a CChain for the main branch.
7474
CChain chain;
75-
chain.SetTip(&vBlocksMain.back());
75+
chain.SetTip(vBlocksMain.back());
7676

7777
// Test 100 random starting points for locators.
7878
for (int n=0; n<100; n++) {
@@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(findearliestatleast_test)
128128

129129
// Build a CChain for the main branch.
130130
CChain chain;
131-
chain.SetTip(&vBlocksMain.back());
131+
chain.SetTip(vBlocksMain.back());
132132

133133
// Verify that FindEarliestAtLeast is correct.
134134
for (unsigned int i=0; i<10000; ++i) {
@@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(findearliestatleast_edge_test)
155155
}
156156

157157
CChain chain;
158-
chain.SetTip(&blocks.back());
158+
chain.SetTip(blocks.back());
159159

160160
BOOST_CHECK_EQUAL(chain.FindEarliestAtLeast(50, 0)->nHeight, 0);
161161
BOOST_CHECK_EQUAL(chain.FindEarliestAtLeast(100, 0)->nHeight, 0);

src/validation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,6 +2578,7 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr
25782578

25792579
CBlockIndex *pindexDelete = m_chain.Tip();
25802580
assert(pindexDelete);
2581+
assert(pindexDelete->pprev);
25812582
// Read block from disk.
25822583
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
25832584
CBlock& block = *pblock;
@@ -2625,7 +2626,7 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr
26252626
}
26262627
}
26272628

2628-
m_chain.SetTip(pindexDelete->pprev);
2629+
m_chain.SetTip(*pindexDelete->pprev);
26292630

26302631
UpdateTip(pindexDelete->pprev);
26312632
// Let wallets know transactions went from 1-confirmed to
@@ -2739,7 +2740,7 @@ bool CChainState::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew
27392740
disconnectpool.removeForBlock(blockConnecting.vtx);
27402741
}
27412742
// Update m_chain & related variables.
2742-
m_chain.SetTip(pindexNew);
2743+
m_chain.SetTip(*pindexNew);
27432744
UpdateTip(pindexNew);
27442745

27452746
int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
@@ -3887,7 +3888,7 @@ bool CChainState::LoadChainTip()
38873888
if (!pindex) {
38883889
return false;
38893890
}
3890-
m_chain.SetTip(pindex);
3891+
m_chain.SetTip(*pindex);
38913892
PruneBlockIndexCandidates();
38923893

38933894
tip = m_chain.Tip();
@@ -4964,7 +4965,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
49644965
return false;
49654966
}
49664967

4967-
snapshot_chainstate.m_chain.SetTip(snapshot_start_block);
4968+
snapshot_chainstate.m_chain.SetTip(*snapshot_start_block);
49684969

49694970
// The remainder of this function requires modifying data protected by cs_main.
49704971
LOCK(::cs_main);

0 commit comments

Comments
 (0)