Skip to content

Commit 528795d

Browse files
committed
merge bitcoin#25023: Remove unused SetTip(nullptr) code
1 parent 6c8a8f7 commit 528795d

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
@@ -19,11 +19,9 @@ std::string CBlockIndex::ToString() const
1919
pprev, nHeight, hashMerkleRoot.ToString(), GetBlockHash().ToString());
2020
}
2121

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

src/chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ class CChain
470470
}
471471

472472
/** Set/initialize a chain with a given tip. */
473-
void SetTip(CBlockIndex* pindex);
473+
void SetTip(CBlockIndex& block);
474474

475475
/** Return a CBlockLocator that refers to a block in this chain (by default the tip). */
476476
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
@@ -386,7 +386,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
386386
// next->pprev = prev;
387387
// next->nHeight = prev->nHeight + 1;
388388
// next->BuildSkip();
389-
// m_node.chainman->ActiveChain().SetTip(next);
389+
// m_node.chainman->ActiveChain().SetTip(*next);
390390
// }
391391
//BOOST_CHECK(pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey));
392392
// // Extend to a 210000-long block chain.
@@ -398,7 +398,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
398398
// next->pprev = prev;
399399
// next->nHeight = prev->nHeight + 1;
400400
// next->BuildSkip();
401-
// m_node.chainman->ActiveChain().SetTip(next);
401+
// m_node.chainman->ActiveChain().SetTip(*next);
402402
// }
403403
//BOOST_CHECK(pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey));
404404

@@ -423,7 +423,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
423423
// // Delete the dummy blocks again.
424424
// while (m_node.chainman->ActiveChain().Tip()->nHeight > nHeight) {
425425
// CBlockIndex* del = m_node.chainman->ActiveChain().Tip();
426-
// m_node.chainman->ActiveChain().SetTip(del->pprev);
426+
// m_node.chainman->ActiveChain().SetTip(*Assert(del->pprev));
427427
// m_node.chainman->ActiveChainstate().CoinsTip().SetBestBlock(del->pprev->GetBlockHash());
428428
// delete del->phashBlock;
429429
// 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
@@ -2922,6 +2922,7 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr
29222922

29232923
CBlockIndex *pindexDelete = m_chain.Tip();
29242924
assert(pindexDelete);
2925+
assert(pindexDelete->pprev);
29252926
// Read block from disk.
29262927
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
29272928
CBlock& block = *pblock;
@@ -2972,7 +2973,7 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr
29722973
}
29732974
}
29742975

2975-
m_chain.SetTip(pindexDelete->pprev);
2976+
m_chain.SetTip(*pindexDelete->pprev);
29762977

29772978
UpdateTip(pindexDelete->pprev);
29782979
// Let wallets know transactions went from 1-confirmed to
@@ -3103,7 +3104,7 @@ bool CChainState::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew
31033104
disconnectpool.removeForBlock(blockConnecting.vtx);
31043105
}
31053106
// Update m_chain & related variables.
3106-
m_chain.SetTip(pindexNew);
3107+
m_chain.SetTip(*pindexNew);
31073108
UpdateTip(pindexNew);
31083109

31093110
int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
@@ -4448,7 +4449,7 @@ bool CChainState::LoadChainTip()
44484449
if (!pindex) {
44494450
return false;
44504451
}
4451-
m_chain.SetTip(pindex);
4452+
m_chain.SetTip(*pindex);
44524453
PruneBlockIndexCandidates();
44534454

44544455
tip = m_chain.Tip();
@@ -5827,7 +5828,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
58275828
return false;
58285829
}
58295830

5830-
snapshot_chainstate.m_chain.SetTip(snapshot_start_block);
5831+
snapshot_chainstate.m_chain.SetTip(*snapshot_start_block);
58315832

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

0 commit comments

Comments
 (0)