* Handle invalid block rejection and consequent peer discouragement, maintain which * peers announce compact blocks. */
| 2223 | * peers announce compact blocks. |
| 2224 | */ |
| 2225 | void PeerManagerImpl::BlockChecked(const std::shared_ptr<const CBlock>& block, const BlockValidationState& state) |
| 2226 | { |
| 2227 | LOCK(cs_main); |
| 2228 | |
| 2229 | const uint256 hash(block->GetHash()); |
| 2230 | std::map<uint256, std::pair<NodeId, bool>>::iterator it = mapBlockSource.find(hash); |
| 2231 | |
| 2232 | // If the block failed validation, we know where it came from and we're still connected |
| 2233 | // to that peer, maybe punish. |
| 2234 | if (state.IsInvalid() && |
| 2235 | it != mapBlockSource.end() && |
| 2236 | State(it->second.first)) { |
| 2237 | MaybePunishNodeForBlock(/*nodeid=*/ it->second.first, state, /*via_compact_block=*/ !it->second.second); |
| 2238 | } |
| 2239 | // Check that: |
| 2240 | // 1. The block is valid |
| 2241 | // 2. We're not in initial block download |
| 2242 | // 3. This is currently the best block we're aware of. We haven't updated |
| 2243 | // the tip yet so we have no way to check this directly here. Instead we |
| 2244 | // just check that there are currently no other blocks in flight. |
| 2245 | else if (state.IsValid() && |
| 2246 | !m_chainman.IsInitialBlockDownload() && |
| 2247 | mapBlocksInFlight.count(hash) == mapBlocksInFlight.size()) { |
| 2248 | if (it != mapBlockSource.end()) { |
| 2249 | MaybeSetPeerAsAnnouncingHeaderAndIDs(it->second.first); |
| 2250 | } |
| 2251 | } |
| 2252 | if (it != mapBlockSource.end()) |
| 2253 | mapBlockSource.erase(it); |
| 2254 | } |
| 2255 | |
| 2256 | ////////////////////////////////////////////////////////////////////////////// |
| 2257 | // |