Modernize best block mutex/cv/hash variable naming

(cherry picked from commit bitcoin/bitcoin@4a6c0e3dcf)
This commit is contained in:
Pieter Wuille 2018-04-03 21:53:07 -07:00 committed by Larry Ruane
parent 4693f8165f
commit c079a518c0
4 changed files with 18 additions and 18 deletions

View File

@ -305,7 +305,7 @@ bool static Bind(const CService &addr, unsigned int flags) {
void OnRPCStopped()
{
cvBlockChange.notify_all();
g_best_block_cv.notify_all();
LogPrint("rpc", "RPC stopped.\n");
}

View File

@ -66,10 +66,10 @@ BlockMap mapBlockIndex;
CChain chainActive;
CBlockIndex *pindexBestHeader = NULL;
static std::atomic<int64_t> nTimeBestReceived(0); // Used only to inform the wallet of when we last received a block
CWaitableCriticalSection csBestBlock;
CConditionVariable cvBlockChange;
uint256 hashBestBlock;
int heightBestBlock;
CWaitableCriticalSection g_best_block_mutex;
CConditionVariable g_best_block_cv;
uint256 g_best_block;
int g_best_block_height;
int nScriptCheckThreads = 0;
std::atomic_bool fImporting(false);
std::atomic_bool fReindex(false);
@ -3760,10 +3760,10 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
RenderPoolMetrics("transparent", transparentPool);
{
boost::unique_lock<boost::mutex> lock(csBestBlock);
hashBestBlock = pindexNew->GetBlockHash();
heightBestBlock = pindexNew->nHeight;
cvBlockChange.notify_all();
boost::unique_lock<boost::mutex> lock(g_best_block_mutex);
g_best_block = pindexNew->GetBlockHash();
g_best_block_height = pindexNew->nHeight;
g_best_block_cv.notify_all();
}
}

View File

@ -162,10 +162,10 @@ extern std::optional<uint64_t> last_block_size;
extern const std::string strMessageMagic;
// These prevent lock-ordering problems in getblocktemplate() RPC
extern CWaitableCriticalSection csBestBlock;
extern CConditionVariable cvBlockChange;
extern uint256 hashBestBlock;
extern int heightBestBlock;
extern CWaitableCriticalSection g_best_block_mutex;
extern CConditionVariable g_best_block_cv;
extern uint256 g_best_block;
extern int g_best_block_height;
extern std::atomic_bool fImporting;
extern std::atomic_bool fReindex;

View File

@ -613,8 +613,8 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
{
checktxtime = boost::get_system_time() + boost::posix_time::seconds(10);
boost::unique_lock<boost::mutex> lock(csBestBlock);
while (hashBestBlock == hashWatchedChain && IsRPCRunning())
boost::unique_lock<boost::mutex> lock(g_best_block_mutex);
while (g_best_block == hashWatchedChain && IsRPCRunning())
{
// Before waiting, generate the coinbase for the block following the next
// block (since this is cpu-intensive), so that when next block arrives,
@ -628,11 +628,11 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
Params(), CAmount{0}, minerAddress, cached_next_cb_height);
next_cb_mtx = cached_next_cb_mtx;
}
bool timedout = !cvBlockChange.timed_wait(lock, checktxtime);
bool timedout = !g_best_block_cv.timed_wait(lock, checktxtime);
// Optimization: even if timed out, a new block may have arrived
// while waiting for cs_main; if so, don't discard next_cb_mtx.
if (hashBestBlock != hashWatchedChain) break;
if (g_best_block != hashWatchedChain) break;
// Timeout: Check transactions for update
if (timedout && mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP) {
@ -642,7 +642,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
}
checktxtime += boost::posix_time::seconds(10);
}
if (heightBestBlock != nHeight + 1) {
if (g_best_block_height != nHeight + 1) {
// Unexpected height (reorg or >1 blocks arrived while waiting) invalidates coinbase tx.
next_cb_mtx = nullopt;
}