MCPcopy Create free account
hub / github.com/ElementsProject/elements / PrepareBlockFilterRequest

Method PrepareBlockFilterRequest

src/net_processing.cpp:2399–2450  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2397}
2398
2399bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
2400 BlockFilterType filter_type, uint32_t start_height,
2401 const uint256& stop_hash, uint32_t max_height_diff,
2402 const CBlockIndex*& stop_index,
2403 BlockFilterIndex*& filter_index)
2404{
2405 const bool supported_filter_type =
2406 (filter_type == BlockFilterType::BASIC &&
2407 (peer.GetLocalServices() & NODE_COMPACT_FILTERS));
2408 if (!supported_filter_type) {
2409 LogPrint(BCLog::NET, "peer %d requested unsupported block filter type: %d\n",
2410 peer.GetId(), static_cast<uint8_t>(filter_type));
2411 peer.fDisconnect = true;
2412 return false;
2413 }
2414
2415 {
2416 LOCK(cs_main);
2417 stop_index = m_chainman.m_blockman.LookupBlockIndex(stop_hash);
2418
2419 // Check that the stop block exists and the peer would be allowed to fetch it.
2420 if (!stop_index || !BlockRequestAllowed(stop_index)) {
2421 LogPrint(BCLog::NET, "peer %d requested invalid block hash: %s\n",
2422 peer.GetId(), stop_hash.ToString());
2423 peer.fDisconnect = true;
2424 return false;
2425 }
2426 }
2427
2428 uint32_t stop_height = stop_index->nHeight;
2429 if (start_height > stop_height) {
2430 LogPrint(BCLog::NET, "peer %d sent invalid getcfilters/getcfheaders with " /* Continued */
2431 "start height %d and stop height %d\n",
2432 peer.GetId(), start_height, stop_height);
2433 peer.fDisconnect = true;
2434 return false;
2435 }
2436 if (stop_height - start_height >= max_height_diff) {
2437 LogPrint(BCLog::NET, "peer %d requested too many cfilters/cfheaders: %d / %d\n",
2438 peer.GetId(), stop_height - start_height + 1, max_height_diff);
2439 peer.fDisconnect = true;
2440 return false;
2441 }
2442
2443 filter_index = GetBlockFilterIndex(filter_type);
2444 if (!filter_index) {
2445 LogPrint(BCLog::NET, "Filter index for supported type %s not found\n", BlockFilterTypeName(filter_type));
2446 return false;
2447 }
2448
2449 return true;
2450}
2451
2452void PeerManagerImpl::ProcessGetCFilters(CNode& peer, CDataStream& vRecv)
2453{

Callers

nothing calls this directly

Calls 5

GetBlockFilterIndexFunction · 0.85
GetIdMethod · 0.80
LookupBlockIndexMethod · 0.80
GetLocalServicesMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected