Skip to content

Commit 0a3b8ea

Browse files
committed
Merge bitcoin/bitcoin#22106: refactor: address ProcessNewBlock comments from #21713
e12f287 net: cleanup newly added PeerManagerImpl::ProcessNewBlock (fanquake) 610151f validation: change ProcessNewBlock() to take a CBlock reference (fanquake) Pull request description: Addresses some [post-merge comments](bitcoin/bitcoin#21713 (review)) from #21713. Also makes `ChainstateManager::ProcessNewBlock` take a const reference argument, as it [was asked](bitcoin/bitcoin#21713 (comment)) why it was not the case in that PR. ACKs for top commit: jnewbery: Code review ACK e12f287 MarcoFalke: review ACK e12f287 🚚 Tree-SHA512: 9c3e7353240c862d50bce2a0f58741c109dd628040b56ed46250103f8ebe9009238b131da710486791e28e3a83c985057b7be0a32aed1a929269b43097c7425b
2 parents 7e83e74 + e12f287 commit 0a3b8ea

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

src/net_processing.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ class PeerManagerImpl final : public PeerManager
491491

492492
void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(peer.m_getdata_requests_mutex) LOCKS_EXCLUDED(::cs_main);
493493

494-
void ProcessBlock(CNode& pfrom, const std::shared_ptr<const CBlock>& pblock, bool fForceProcessing);
494+
/** Process a new block. Perform any post-processing housekeeping */
495+
void ProcessBlock(CNode& node, const std::shared_ptr<const CBlock>& block, bool force_processing);
495496

496497
/** Relay map (txid or wtxid -> CTransactionRef) */
497498
typedef std::map<uint256, CTransactionRef> MapRelay;
@@ -2384,15 +2385,15 @@ void PeerManagerImpl::ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv)
23842385
m_connman.PushMessage(&peer, std::move(msg));
23852386
}
23862387

2387-
void PeerManagerImpl::ProcessBlock(CNode& pfrom, const std::shared_ptr<const CBlock>& pblock, bool fForceProcessing)
2388+
void PeerManagerImpl::ProcessBlock(CNode& node, const std::shared_ptr<const CBlock>& block, bool force_processing)
23882389
{
2389-
bool fNewBlock = false;
2390-
m_chainman.ProcessNewBlock(m_chainparams, pblock, fForceProcessing, &fNewBlock);
2391-
if (fNewBlock) {
2392-
pfrom.nLastBlockTime = GetTime();
2390+
bool new_block{false};
2391+
m_chainman.ProcessNewBlock(m_chainparams, block, force_processing, &new_block);
2392+
if (new_block) {
2393+
node.nLastBlockTime = GetTime();
23932394
} else {
23942395
LOCK(cs_main);
2395-
mapBlockSource.erase(pblock->GetHash());
2396+
mapBlockSource.erase(block->GetHash());
23962397
}
23972398
}
23982399

@@ -3475,7 +3476,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
34753476
LOCK(cs_main);
34763477
mapBlockSource.emplace(pblock->GetHash(), std::make_pair(pfrom.GetId(), false));
34773478
}
3478-
// Setting fForceProcessing to true means that we bypass some of
3479+
// Setting force_processing to true means that we bypass some of
34793480
// our anti-DoS protections in AcceptBlock, which filters
34803481
// unrequested blocks that might be trying to waste our resources
34813482
// (eg disk space). Because we only try to reconstruct blocks when
@@ -3484,7 +3485,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
34843485
// we have a chain with at least nMinimumChainWork), and we ignore
34853486
// compact blocks with less work than our tip, it is safe to treat
34863487
// reconstructed compact blocks as having been requested.
3487-
ProcessBlock(pfrom, pblock, /*fForceProcessing=*/true);
3488+
ProcessBlock(pfrom, pblock, /*force_processing=*/true);
34883489
LOCK(cs_main); // hold cs_main for CBlockIndex::IsValid()
34893490
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS)) {
34903491
// Clear download state for this block, which is in
@@ -3567,7 +3568,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
35673568
// disk-space attacks), but this should be safe due to the
35683569
// protections in the compact block handler -- see related comment
35693570
// in compact block optimistic reconstruction handling.
3570-
ProcessBlock(pfrom, pblock, /*fForceProcessing=*/true);
3571+
ProcessBlock(pfrom, pblock, /*force_processing=*/true);
35713572
}
35723573
return;
35733574
}

src/validation.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,14 +3591,14 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
35913591
return true;
35923592
}
35933593

3594-
bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock)
3594+
bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock>& block, bool force_processing, bool* new_block)
35953595
{
35963596
AssertLockNotHeld(cs_main);
35973597
assert(std::addressof(::ChainstateActive()) == std::addressof(ActiveChainstate()));
35983598

35993599
{
36003600
CBlockIndex *pindex = nullptr;
3601-
if (fNewBlock) *fNewBlock = false;
3601+
if (new_block) *new_block = false;
36023602
BlockValidationState state;
36033603

36043604
// CheckBlock() does not support multi-threaded block validation because CBlock::fChecked can cause data race.
@@ -3607,21 +3607,21 @@ bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const s
36073607

36083608
// Ensure that CheckBlock() passes before calling AcceptBlock, as
36093609
// belt-and-suspenders.
3610-
bool ret = CheckBlock(*pblock, state, chainparams.GetConsensus());
3610+
bool ret = CheckBlock(*block, state, chainparams.GetConsensus());
36113611
if (ret) {
36123612
// Store to disk
3613-
ret = ActiveChainstate().AcceptBlock(pblock, state, chainparams, &pindex, fForceProcessing, nullptr, fNewBlock);
3613+
ret = ActiveChainstate().AcceptBlock(block, state, chainparams, &pindex, force_processing, nullptr, new_block);
36143614
}
36153615
if (!ret) {
3616-
GetMainSignals().BlockChecked(*pblock, state);
3616+
GetMainSignals().BlockChecked(*block, state);
36173617
return error("%s: AcceptBlock FAILED (%s)", __func__, state.ToString());
36183618
}
36193619
}
36203620

36213621
NotifyHeaderTip(ActiveChainstate());
36223622

36233623
BlockValidationState state; // Only used to report errors, not invalidity - ignore it
3624-
if (!ActiveChainstate().ActivateBestChain(state, chainparams, pblock))
3624+
if (!ActiveChainstate().ActivateBestChain(state, chainparams, block))
36253625
return error("%s: ActivateBestChain failed (%s)", __func__, state.ToString());
36263626

36273627
return true;

src/validation.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -970,22 +970,21 @@ class ChainstateManager
970970
* block is made active. Note that it does not, however, guarantee that the
971971
* specific block passed to it has been checked for validity!
972972
*
973-
* If you want to *possibly* get feedback on whether pblock is valid, you must
973+
* If you want to *possibly* get feedback on whether block is valid, you must
974974
* install a CValidationInterface (see validationinterface.h) - this will have
975975
* its BlockChecked method called whenever *any* block completes validation.
976976
*
977-
* Note that we guarantee that either the proof-of-work is valid on pblock, or
977+
* Note that we guarantee that either the proof-of-work is valid on block, or
978978
* (and possibly also) BlockChecked will have been called.
979979
*
980-
* May not be called in a
981-
* validationinterface callback.
980+
* May not be called in a validationinterface callback.
982981
*
983-
* @param[in] pblock The block we want to process.
984-
* @param[in] fForceProcessing Process this block even if unrequested; used for non-network block sources.
985-
* @param[out] fNewBlock A boolean which is set to indicate if the block was first received via this call
982+
* @param[in] block The block we want to process.
983+
* @param[in] force_processing Process this block even if unrequested; used for non-network block sources.
984+
* @param[out] new_block A boolean which is set to indicate if the block was first received via this call
986985
* @returns If the block was processed, independently of block validity
987986
*/
988-
bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock) LOCKS_EXCLUDED(cs_main);
987+
bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock>& block, bool force_processing, bool* new_block) LOCKS_EXCLUDED(cs_main);
989988

990989
/**
991990
* Process incoming block headers.

0 commit comments

Comments
 (0)