| 3287 | } |
| 3288 | |
| 3289 | void PeerManagerImpl::ProcessGetBlockData(const Config &config, CNode &pfrom, |
| 3290 | Peer &peer, const CInv &inv) { |
| 3291 | const BlockHash hash(inv.hash); |
| 3292 | |
| 3293 | std::shared_ptr<const CBlock> a_recent_block; |
| 3294 | std::shared_ptr<const CBlockHeaderAndShortTxIDs> a_recent_compact_block; |
| 3295 | { |
| 3296 | LOCK(m_most_recent_block_mutex); |
| 3297 | a_recent_block = m_most_recent_block; |
| 3298 | a_recent_compact_block = m_most_recent_compact_block; |
| 3299 | } |
| 3300 | |
| 3301 | bool need_activate_chain = false; |
| 3302 | { |
| 3303 | LOCK(cs_main); |
| 3304 | const CBlockIndex *pindex = |
| 3305 | m_chainman.m_blockman.LookupBlockIndex(hash); |
| 3306 | if (pindex) { |
| 3307 | if (pindex->HaveNumChainTxs() && |
| 3308 | !pindex->IsValid(BlockValidity::SCRIPTS) && |
| 3309 | pindex->IsValid(BlockValidity::TREE)) { |
| 3310 | // If we have the block and all of its parents, but have not yet |
| 3311 | // validated it, we might be in the middle of connecting it (ie |
| 3312 | // in the unlock of cs_main before ActivateBestChain but after |
| 3313 | // AcceptBlock). In this case, we need to run ActivateBestChain |
| 3314 | // prior to checking the relay conditions below. |
| 3315 | need_activate_chain = true; |
| 3316 | } |
| 3317 | } |
| 3318 | } // release cs_main before calling ActivateBestChain |
| 3319 | if (need_activate_chain) { |
| 3320 | BlockValidationState state; |
| 3321 | if (!m_chainman.ActiveChainstate().ActivateBestChain( |
| 3322 | state, a_recent_block, m_avalanche)) { |
| 3323 | LogPrint(BCLog::NET, "failed to activate chain (%s)\n", |
| 3324 | state.ToString()); |
| 3325 | } |
| 3326 | } |
| 3327 | |
| 3328 | const CBlockIndex *pindex{nullptr}; |
| 3329 | const CBlockIndex *tip{nullptr}; |
| 3330 | bool can_direct_fetch{false}; |
| 3331 | FlatFilePos block_pos{}; |
| 3332 | { |
| 3333 | LOCK(cs_main); |
| 3334 | pindex = m_chainman.m_blockman.LookupBlockIndex(hash); |
| 3335 | if (!pindex) { |
| 3336 | return; |
| 3337 | } |
| 3338 | if (!BlockRequestAllowed(pindex)) { |
| 3339 | LogPrint(BCLog::NET, |
| 3340 | "%s: ignoring request from peer=%i for old " |
| 3341 | "block that isn't in the main chain\n", |
| 3342 | __func__, pfrom.GetId()); |
| 3343 | return; |
| 3344 | } |
| 3345 | // Disconnect node in case we have reached the outbound limit for |
| 3346 | // serving historical blocks. |
nothing calls this directly
no test coverage detected