Skip to content

Commit f0a2fb3

Browse files
committed
scripted-diff: Rename pindexBestHeader, fHavePruned
...to m_best_header and m_have_pruned -BEGIN VERIFY SCRIPT- find_regex="\bpindexBestHeader\b" \ && git grep -l -E "$find_regex" -- src \ | xargs sed -i -E "s@$find_regex@m_best_header@g" find_regex="\bfHavePruned\b" \ && git grep -l -E "$find_regex" -- src \ | xargs sed -i -E "s@$find_regex@m_have_pruned@g" -END VERIFY SCRIPT-
1 parent a401402 commit f0a2fb3

File tree

9 files changed

+48
-48
lines changed

9 files changed

+48
-48
lines changed

src/init.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14791479
try {
14801480
uiInterface.InitMessage(_("Verifying blocks…").translated);
14811481
auto check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
1482-
if (chainman.m_blockman.fHavePruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
1482+
if (chainman.m_blockman.m_have_pruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
14831483
LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks\n",
14841484
MIN_BLOCKS_TO_KEEP);
14851485
}
@@ -1663,9 +1663,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16631663
tip_info->block_time = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockTime() : Params().GenesisBlock().GetBlockTime();
16641664
tip_info->verification_progress = GuessVerificationProgress(Params().TxData(), chainman.ActiveChain().Tip());
16651665
}
1666-
if (tip_info && chainman.pindexBestHeader) {
1667-
tip_info->header_height = chainman.pindexBestHeader->nHeight;
1668-
tip_info->header_time = chainman.pindexBestHeader->GetBlockTime();
1666+
if (tip_info && chainman.m_best_header) {
1667+
tip_info->header_height = chainman.m_best_header->nHeight;
1668+
tip_info->header_time = chainman.m_best_header->GetBlockTime();
16691669
}
16701670
}
16711671
LogPrintf("nBestHeight = %d\n", chain_active_height);

src/net_processing.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,9 +1499,9 @@ bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex* pindex)
14991499
{
15001500
AssertLockHeld(cs_main);
15011501
if (m_chainman.ActiveChain().Contains(pindex)) return true;
1502-
return pindex->IsValid(BLOCK_VALID_SCRIPTS) && (m_chainman.pindexBestHeader != nullptr) &&
1503-
(m_chainman.pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() < STALE_RELAY_AGE_LIMIT) &&
1504-
(GetBlockProofEquivalentTime(*m_chainman.pindexBestHeader, *pindex, *m_chainman.pindexBestHeader, m_chainparams.GetConsensus()) < STALE_RELAY_AGE_LIMIT);
1502+
return pindex->IsValid(BLOCK_VALID_SCRIPTS) && (m_chainman.m_best_header != nullptr) &&
1503+
(m_chainman.m_best_header->GetBlockTime() - pindex->GetBlockTime() < STALE_RELAY_AGE_LIMIT) &&
1504+
(GetBlockProofEquivalentTime(*m_chainman.m_best_header, *pindex, *m_chainman.m_best_header, m_chainparams.GetConsensus()) < STALE_RELAY_AGE_LIMIT);
15051505
}
15061506

15071507
std::optional<std::string> PeerManagerImpl::FetchBlock(NodeId peer_id, const CBlockIndex& block_index)
@@ -1896,7 +1896,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
18961896
const CNetMsgMaker msgMaker(pfrom.GetCommonVersion());
18971897
// disconnect node in case we have reached the outbound limit for serving historical blocks
18981898
if (m_connman.OutboundTargetReached(true) &&
1899-
(((m_chainman.pindexBestHeader != nullptr) && (m_chainman.pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk()) &&
1899+
(((m_chainman.m_best_header != nullptr) && (m_chainman.m_best_header->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk()) &&
19001900
!pfrom.HasPermission(NetPermissionFlags::Download) // nodes with the download permission may exceed target
19011901
) {
19021902
LogPrint(BCLog::NET, "historical block serving limit reached, disconnect peer=%d\n", pfrom.GetId());
@@ -2173,11 +2173,11 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
21732173
// nUnconnectingHeaders gets reset back to 0.
21742174
if (!m_chainman.m_blockman.LookupBlockIndex(headers[0].hashPrevBlock) && nCount < MAX_BLOCKS_TO_ANNOUNCE) {
21752175
nodestate->nUnconnectingHeaders++;
2176-
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, m_chainman.ActiveChain().GetLocator(m_chainman.pindexBestHeader), uint256()));
2176+
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, m_chainman.ActiveChain().GetLocator(m_chainman.m_best_header), uint256()));
21772177
LogPrint(BCLog::NET, "received header %s: missing prev block %s, sending getheaders (%d) to end (peer=%d, nUnconnectingHeaders=%d)\n",
21782178
headers[0].GetHash().ToString(),
21792179
headers[0].hashPrevBlock.ToString(),
2180-
m_chainman.pindexBestHeader->nHeight,
2180+
m_chainman.m_best_header->nHeight,
21812181
pfrom.GetId(), nodestate->nUnconnectingHeaders);
21822182
// Set hashLastUnknownBlock for this peer, so that if we
21832183
// eventually get the headers - even from a different peer -
@@ -2235,7 +2235,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
22352235

22362236
if (nCount == MAX_HEADERS_RESULTS) {
22372237
// Headers message had its maximum size; the peer may have more headers.
2238-
// TODO: optimize: if pindexLast is an ancestor of m_chainman.ActiveChain().Tip or m_chainman.pindexBestHeader, continue
2238+
// TODO: optimize: if pindexLast is an ancestor of m_chainman.ActiveChain().Tip or m_chainman.m_best_header, continue
22392239
// from there instead.
22402240
LogPrint(BCLog::NET, "more getheaders (%d) to end to peer=%d (startheight:%d)\n",
22412241
pindexLast->nHeight, pfrom.GetId(), peer.m_starting_height);
@@ -3102,8 +3102,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
31023102
}
31033103

31043104
if (best_block != nullptr) {
3105-
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, m_chainman.ActiveChain().GetLocator(m_chainman.pindexBestHeader), *best_block));
3106-
LogPrint(BCLog::NET, "getheaders (%d) %s to peer=%d\n", m_chainman.pindexBestHeader->nHeight, best_block->ToString(), pfrom.GetId());
3105+
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, m_chainman.ActiveChain().GetLocator(m_chainman.m_best_header), *best_block));
3106+
LogPrint(BCLog::NET, "getheaders (%d) %s to peer=%d\n", m_chainman.m_best_header->nHeight, best_block->ToString(), pfrom.GetId());
31073107
}
31083108

31093109
return;
@@ -3549,7 +3549,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
35493549
if (!m_chainman.m_blockman.LookupBlockIndex(cmpctblock.header.hashPrevBlock)) {
35503550
// Doesn't connect (or is genesis), instead of DoSing in AcceptBlockHeader, request deeper headers
35513551
if (!m_chainman.ActiveChainstate().IsInitialBlockDownload())
3552-
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, m_chainman.ActiveChain().GetLocator(m_chainman.pindexBestHeader), uint256()));
3552+
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, m_chainman.ActiveChain().GetLocator(m_chainman.m_best_header), uint256()));
35533553
return;
35543554
}
35553555

@@ -4670,29 +4670,29 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
46704670
CNodeState &state = *State(pto->GetId());
46714671

46724672
// Start block sync
4673-
if (m_chainman.pindexBestHeader == nullptr) {
4674-
m_chainman.pindexBestHeader = m_chainman.ActiveChain().Tip();
4673+
if (m_chainman.m_best_header == nullptr) {
4674+
m_chainman.m_best_header = m_chainman.ActiveChain().Tip();
46754675
}
46764676
bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->IsAddrFetchConn()); // Download if this is a nice peer, or we have no nice peers and this one might do.
46774677
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) {
46784678
// Only actively request headers from a single peer, unless we're close to today.
4679-
if ((nSyncStarted == 0 && fFetch) || m_chainman.pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) {
4679+
if ((nSyncStarted == 0 && fFetch) || m_chainman.m_best_header->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) {
46804680
state.fSyncStarted = true;
46814681
state.m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE +
46824682
(
46834683
// Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling
46844684
// to maintain precision
46854685
std::chrono::microseconds{HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER} *
4686-
(GetAdjustedTime() - m_chainman.pindexBestHeader->GetBlockTime()) / consensusParams.nPowTargetSpacing
4686+
(GetAdjustedTime() - m_chainman.m_best_header->GetBlockTime()) / consensusParams.nPowTargetSpacing
46874687
);
46884688
nSyncStarted++;
4689-
const CBlockIndex* pindexStart = m_chainman.pindexBestHeader;
4689+
const CBlockIndex* pindexStart = m_chainman.m_best_header;
46904690
/* If possible, start at the block preceding the currently
46914691
best known header. This ensures that we always get a
46924692
non-empty list of headers back as long as the peer
46934693
is up-to-date. With a non-empty response, we can initialise
46944694
the peer's known best block. This wouldn't be possible
4695-
if we requested starting at m_chainman.pindexBestHeader and
4695+
if we requested starting at m_chainman.m_best_header and
46964696
got back an empty response. */
46974697
if (pindexStart->pprev)
46984698
pindexStart = pindexStart->pprev;
@@ -5017,7 +5017,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
50175017
// Check for headers sync timeouts
50185018
if (state.fSyncStarted && state.m_headers_sync_timeout < std::chrono::microseconds::max()) {
50195019
// Detect whether this is a stalling initial-headers-sync peer
5020-
if (m_chainman.pindexBestHeader->GetBlockTime() <= GetAdjustedTime() - 24 * 60 * 60) {
5020+
if (m_chainman.m_best_header->GetBlockTime() <= GetAdjustedTime() - 24 * 60 * 60) {
50215021
if (current_time > state.m_headers_sync_timeout && nSyncStarted == 1 && (nPreferredDownload - state.fPreferredDownload >= 1)) {
50225022
// Disconnect a peer (without NetPermissionFlags::NoBan permission) if it is our only sync peer,
50235023
// and we have others we could be using instead.

src/node/blockstorage.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ void BlockManager::Unload()
301301
m_dirty_blockindex.clear();
302302
m_dirty_fileinfo.clear();
303303

304-
fHavePruned = false;
304+
m_have_pruned = false;
305305
}
306306

307307
bool BlockManager::WriteBlockIndexDB()
@@ -364,8 +364,8 @@ bool BlockManager::LoadBlockIndexDB()
364364
}
365365

366366
// Check whether we have ever pruned block & undo files
367-
m_block_tree_db->ReadFlag("prunedblockfiles", fHavePruned);
368-
if (fHavePruned) {
367+
m_block_tree_db->ReadFlag("prunedblockfiles", m_have_pruned);
368+
if (m_have_pruned) {
369369
LogPrintf("LoadBlockIndexDB(): Block files have previously been pruned\n");
370370
}
371371

@@ -394,7 +394,7 @@ const CBlockIndex* BlockManager::GetLastCheckpoint(const CCheckpointData& data)
394394
bool BlockManager::IsBlockPruned(const CBlockIndex* pblockindex)
395395
{
396396
AssertLockHeld(::cs_main);
397-
return (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
397+
return (m_have_pruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
398398
}
399399

400400
// If we're using -prune with -reindex, then delete block files that will be ignored by the

src/node/blockstorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class BlockManager
170170
const CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
171171

172172
/** True if any block files have ever been pruned. */
173-
bool fHavePruned = false;
173+
bool m_have_pruned = false;
174174

175175
//! Check whether the block associated with this index entry is pruned or not.
176176
bool IsBlockPruned(const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);

src/node/chainstate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
4949

5050
if (shutdown_requested && shutdown_requested()) return ChainstateLoadingError::SHUTDOWN_PROBED;
5151

52-
// LoadBlockIndex will load fHavePruned if we've ever removed a
52+
// LoadBlockIndex will load m_have_pruned if we've ever removed a
5353
// block file from disk.
5454
// Note that it also sets fReindex based on the disk flag!
5555
// From here on out fReindex and fReset mean something different!
@@ -65,7 +65,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
6565

6666
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
6767
// in the past, but is now trying to run unpruned.
68-
if (chainman.m_blockman.fHavePruned && !fPruneMode) {
68+
if (chainman.m_blockman.m_have_pruned && !fPruneMode) {
6969
return ChainstateLoadingError::ERROR_PRUNED_NEEDS_REINDEX;
7070
}
7171

src/node/interfaces.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class NodeImpl : public Node
212212
bool getHeaderTip(int& height, int64_t& block_time) override
213213
{
214214
LOCK(::cs_main);
215-
auto best_header = chainman().pindexBestHeader;
215+
auto best_header = chainman().m_best_header;
216216
if (best_header) {
217217
height = best_header->nHeight;
218218
block_time = best_header->GetBlockTime();
@@ -645,7 +645,7 @@ class ChainImpl : public Chain
645645
bool havePruned() override
646646
{
647647
LOCK(cs_main);
648-
return m_node.chainman->m_blockman.fHavePruned;
648+
return m_node.chainman->m_blockman.m_have_pruned;
649649
}
650650
bool isReadyToBroadcast() override { return !node::fImporting && !node::fReindex && !isInitialBlockDownload(); }
651651
bool isInitialBlockDownload() override {

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ RPCHelpMan getblockchaininfo()
12061206
UniValue obj(UniValue::VOBJ);
12071207
obj.pushKV("chain", Params().NetworkIDString());
12081208
obj.pushKV("blocks", height);
1209-
obj.pushKV("headers", chainman.pindexBestHeader ? chainman.pindexBestHeader->nHeight : -1);
1209+
obj.pushKV("headers", chainman.m_best_header ? chainman.m_best_header->nHeight : -1);
12101210
obj.pushKV("bestblockhash", tip->GetBlockHash().GetHex());
12111211
obj.pushKV("difficulty", (double)GetDifficulty(tip));
12121212
obj.pushKV("time", (int64_t)tip->nTime);

0 commit comments

Comments
 (0)