MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / PrepareBlockFilterRequest

Method PrepareBlockFilterRequest

src/net_processing.cpp:3293–3344  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3291}
3292
3293bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& node, Peer& peer,
3294 BlockFilterType filter_type, uint32_t start_height,
3295 const uint256& stop_hash, uint32_t max_height_diff,
3296 const CBlockIndex*& stop_index,
3297 BlockFilterIndex*& filter_index)
3298{
3299 const bool supported_filter_type =
3300 (filter_type == BlockFilterType::BASIC &&
3301 (peer.m_our_services & NODE_COMPACT_FILTERS));
3302 if (!supported_filter_type) {
3303 LogDebug(BCLog::NET, "peer requested unsupported block filter type: %d, %s",
3304 static_cast<uint8_t>(filter_type), node.DisconnectMsg());
3305 node.fDisconnect = true;
3306 return false;
3307 }
3308
3309 {
3310 LOCK(cs_main);
3311 stop_index = m_chainman.m_blockman.LookupBlockIndex(stop_hash);
3312
3313 // Check that the stop block exists and the peer would be allowed to fetch it.
3314 if (!stop_index || !BlockRequestAllowed(*stop_index)) {
3315 LogDebug(BCLog::NET, "peer requested invalid block hash: %s, %s",
3316 stop_hash.ToString(), node.DisconnectMsg());
3317 node.fDisconnect = true;
3318 return false;
3319 }
3320 }
3321
3322 uint32_t stop_height = stop_index->nHeight;
3323 if (start_height > stop_height) {
3324 LogDebug(BCLog::NET, "peer sent invalid getcfilters/getcfheaders with "
3325 "start height %d and stop height %d, %s",
3326 start_height, stop_height, node.DisconnectMsg());
3327 node.fDisconnect = true;
3328 return false;
3329 }
3330 if (stop_height - start_height >= max_height_diff) {
3331 LogDebug(BCLog::NET, "peer requested too many cfilters/cfheaders: %d / %d, %s",
3332 stop_height - start_height + 1, max_height_diff, node.DisconnectMsg());
3333 node.fDisconnect = true;
3334 return false;
3335 }
3336
3337 filter_index = GetBlockFilterIndex(filter_type);
3338 if (!filter_index) {
3339 LogDebug(BCLog::NET, "Filter index for supported type %s not found\n", BlockFilterTypeName(filter_type));
3340 return false;
3341 }
3342
3343 return true;
3344}
3345
3346void PeerManagerImpl::ProcessGetCFilters(CNode& node, Peer& peer, DataStream& vRecv)
3347{

Callers

nothing calls this directly

Calls 4

GetBlockFilterIndexFunction · 0.85
DisconnectMsgMethod · 0.80
LookupBlockIndexMethod · 0.80
ToStringMethod · 0.45

Tested by

no test coverage detected