Skip to content

Commit

Permalink
Remove unused g_best_block
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanofsky authored and Sjors committed Sep 3, 2024
1 parent 2019e38 commit d4a7642
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ void StopRPC(const std::any& context)
LogDebug(BCLog::RPC, "Stopping RPC\n");
WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear());
DeleteAuthCookie();
g_best_block_cv.notify_all();
node::NodeContext& node = EnsureAnyNodeContext(context);
// The notifications interface doesn't exist between initialization step 4a and 7.
if (node.notifications) node.notifications->m_tip_block_cv.notify_all();
Expand Down
13 changes: 7 additions & 6 deletions src/test/validation_chainstate_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
#include <chainparams.h>
#include <consensus/validation.h>
#include <node/kernel_notifications.h>
#include <random.h>
#include <rpc/blockchain.h>
#include <sync.h>
Expand Down Expand Up @@ -69,14 +70,14 @@ BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches)
BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
{
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
// be found.
mineBlocks(10);

// 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.
std::shared_ptr<CBlock> pblockone = std::make_shared<CBlock>();
Expand All @@ -91,15 +92,15 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
// Ensure our active chain is the snapshot chainstate.
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.
mineBlocks(1); // Defined in TestChain100Setup.

// 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);

Expand Down Expand Up @@ -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
// validation chain.
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()
10 changes: 0 additions & 10 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ const std::vector<std::string> CHECKLEVEL_DOC {
* */
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
{
AssertLockHeld(cs_main);
Expand Down Expand Up @@ -2987,12 +2983,6 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
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;
if (!m_chainman.IsInitialBlockDownload()) {
const CBlockIndex* pindex = pindexNew;
Expand Down
5 changes: 0 additions & 5 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ enum class SynchronizationState {
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'. */
extern const std::vector<std::string> CHECKLEVEL_DOC;

Expand Down

0 comments on commit d4a7642

Please sign in to comment.