Remove unused g_best_block

This commit is contained in:
Ryan Ofsky 2024-08-26 18:28:07 +02:00 committed by Sjors Provoost
parent e3a560ca68
commit 7942951e3f
No known key found for this signature in database
GPG Key ID: 57FF9BDBCC301009
4 changed files with 7 additions and 22 deletions

View File

@ -303,7 +303,6 @@ void StopRPC(const std::any& context)
LogDebug(BCLog::RPC, "Stopping RPC\n"); LogDebug(BCLog::RPC, "Stopping RPC\n");
WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear()); WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear());
DeleteAuthCookie(); DeleteAuthCookie();
g_best_block_cv.notify_all();
node::NodeContext& node = EnsureAnyNodeContext(context); node::NodeContext& node = EnsureAnyNodeContext(context);
// The notifications interface doesn't exist between initialization step 4a and 7. // The notifications interface doesn't exist between initialization step 4a and 7.
if (node.notifications) node.notifications->m_tip_block_cv.notify_all(); if (node.notifications) node.notifications->m_tip_block_cv.notify_all();

View File

@ -4,6 +4,7 @@
// //
#include <chainparams.h> #include <chainparams.h>
#include <consensus/validation.h> #include <consensus/validation.h>
#include <node/kernel_notifications.h>
#include <random.h> #include <random.h>
#include <rpc/blockchain.h> #include <rpc/blockchain.h>
#include <sync.h> #include <sync.h>
@ -69,14 +70,14 @@ BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches)
BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup) BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
{ {
ChainstateManager& chainman = *Assert(m_node.chainman); ChainstateManager& chainman = *Assert(m_node.chainman);
uint256 curr_tip = ::g_best_block; uint256 curr_tip = m_node.notifications->m_tip_block;
// Mine 10 more blocks, putting at us height 110 where a valid assumeutxo value can // Mine 10 more blocks, putting at us height 110 where a valid assumeutxo value can
// be found. // be found.
mineBlocks(10); mineBlocks(10);
// After adding some blocks to the tip, best block should have changed. // After adding some blocks to the tip, best block should have changed.
BOOST_CHECK(::g_best_block != curr_tip); BOOST_CHECK(m_node.notifications->m_tip_block != curr_tip);
// Grab block 1 from disk; we'll add it to the background chain later. // Grab block 1 from disk; we'll add it to the background chain later.
std::shared_ptr<CBlock> pblockone = std::make_shared<CBlock>(); std::shared_ptr<CBlock> pblockone = std::make_shared<CBlock>();
@ -91,15 +92,15 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
// Ensure our active chain is the snapshot chainstate. // Ensure our active chain is the snapshot chainstate.
BOOST_CHECK(WITH_LOCK(::cs_main, return chainman.IsSnapshotActive())); BOOST_CHECK(WITH_LOCK(::cs_main, return chainman.IsSnapshotActive()));
curr_tip = ::g_best_block; curr_tip = m_node.notifications->m_tip_block;
// Mine a new block on top of the activated snapshot chainstate. // Mine a new block on top of the activated snapshot chainstate.
mineBlocks(1); // Defined in TestChain100Setup. mineBlocks(1); // Defined in TestChain100Setup.
// After adding some blocks to the snapshot tip, best block should have changed. // After adding some blocks to the snapshot tip, best block should have changed.
BOOST_CHECK(::g_best_block != curr_tip); BOOST_CHECK(m_node.notifications->m_tip_block != curr_tip);
curr_tip = ::g_best_block; curr_tip = m_node.notifications->m_tip_block;
BOOST_CHECK_EQUAL(chainman.GetAll().size(), 2); BOOST_CHECK_EQUAL(chainman.GetAll().size(), 2);
@ -138,7 +139,7 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
// g_best_block should be unchanged after adding a block to the background // g_best_block should be unchanged after adding a block to the background
// validation chain. // validation chain.
BOOST_CHECK(block_added); BOOST_CHECK(block_added);
BOOST_CHECK_EQUAL(curr_tip, ::g_best_block); BOOST_CHECK_EQUAL(curr_tip, m_node.notifications->m_tip_block);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View File

@ -108,10 +108,6 @@ const std::vector<std::string> CHECKLEVEL_DOC {
* */ * */
static constexpr int PRUNE_LOCK_BUFFER{10}; static constexpr int PRUNE_LOCK_BUFFER{10};
GlobalMutex g_best_block_mutex;
std::condition_variable g_best_block_cv;
uint256 g_best_block;
const CBlockIndex* Chainstate::FindForkInGlobalIndex(const CBlockLocator& locator) const const CBlockIndex* Chainstate::FindForkInGlobalIndex(const CBlockLocator& locator) const
{ {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
@ -2988,12 +2984,6 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
m_mempool->AddTransactionsUpdated(1); m_mempool->AddTransactionsUpdated(1);
} }
{
LOCK(g_best_block_mutex);
g_best_block = pindexNew->GetBlockHash();
g_best_block_cv.notify_all();
}
std::vector<bilingual_str> warning_messages; std::vector<bilingual_str> warning_messages;
if (!m_chainman.IsInitialBlockDownload()) { if (!m_chainman.IsInitialBlockDownload()) {
const CBlockIndex* pindex = pindexNew; const CBlockIndex* pindex = pindexNew;

View File

@ -85,11 +85,6 @@ enum class SynchronizationState {
POST_INIT POST_INIT
}; };
extern GlobalMutex g_best_block_mutex;
extern std::condition_variable g_best_block_cv;
/** Used to notify getblocktemplate RPC of new tips. */
extern uint256 g_best_block;
/** Documentation for argument 'checklevel'. */ /** Documentation for argument 'checklevel'. */
extern const std::vector<std::string> CHECKLEVEL_DOC; extern const std::vector<std::string> CHECKLEVEL_DOC;