* Handle invalid block rejection and consequent peer discouragement, maintain which * peers announce compact blocks. */
| 1649 | * peers announce compact blocks. |
| 1650 | */ |
| 1651 | void PeerManagerImpl::BlockChecked(const CBlock& block, const BlockValidationState& state) |
| 1652 | { |
| 1653 | LOCK(cs_main); |
| 1654 | |
| 1655 | const uint256 hash(block.GetHash()); |
| 1656 | std::map<uint256, std::pair<NodeId, bool>>::iterator it = mapBlockSource.find(hash); |
| 1657 | |
| 1658 | // If the block failed validation, we know where it came from and we're still connected |
| 1659 | // to that peer, maybe punish. |
| 1660 | if (state.IsInvalid() && |
| 1661 | it != mapBlockSource.end() && |
| 1662 | State(it->second.first)) { |
| 1663 | MaybePunishNodeForBlock(/*nodeid=*/ it->second.first, state, /*via_compact_block=*/ !it->second.second); |
| 1664 | } |
| 1665 | // Check that: |
| 1666 | // 1. The block is valid |
| 1667 | // 2. We're not in initial block download |
| 1668 | // 3. This is currently the best block we're aware of. We haven't updated |
| 1669 | // the tip yet so we have no way to check this directly here. Instead we |
| 1670 | // just check that there are currently no other blocks in flight. |
| 1671 | else if (state.IsValid() && |
| 1672 | !m_chainman.ActiveChainstate().IsInitialBlockDownload() && |
| 1673 | mapBlocksInFlight.count(hash) == mapBlocksInFlight.size()) { |
| 1674 | if (it != mapBlockSource.end()) { |
| 1675 | MaybeSetPeerAsAnnouncingHeaderAndIDs(it->second.first); |
| 1676 | } |
| 1677 | } |
| 1678 | if (it != mapBlockSource.end()) |
| 1679 | mapBlockSource.erase(it); |
| 1680 | } |
| 1681 | |
| 1682 | ////////////////////////////////////////////////////////////////////////////// |
| 1683 | // |