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

Method BlockRequested

src/net_processing.cpp:889–921  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

887}
888
889bool PeerManagerImpl::BlockRequested(NodeId nodeid, const CBlockIndex& block, std::list<QueuedBlock>::iterator** pit)
890{
891 const uint256& hash{block.GetBlockHash()};
892
893 CNodeState *state = State(nodeid);
894 assert(state != nullptr);
895
896 // Short-circuit most stuff in case it is from the same node
897 std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> >::iterator itInFlight = mapBlocksInFlight.find(hash);
898 if (itInFlight != mapBlocksInFlight.end() && itInFlight->second.first == nodeid) {
899 if (pit) {
900 *pit = &itInFlight->second.second;
901 }
902 return false;
903 }
904
905 // Make sure it's not listed somewhere already.
906 RemoveBlockRequest(hash, std::nullopt);
907
908 std::list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
909 {&block, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&m_mempool) : nullptr)});
910 state->nBlocksInFlight++;
911 if (state->nBlocksInFlight == 1) {
912 // We're starting a block download (batch) from this peer.
913 state->m_downloading_since = GetTime<std::chrono::microseconds>();
914 m_peers_downloading_from++;
915 }
916 itInFlight = mapBlocksInFlight.insert(std::make_pair(hash, std::make_pair(nodeid, it))).first;
917 if (pit) {
918 *pit = &itInFlight->second.second;
919 }
920 return true;
921}
922
923void PeerManagerImpl::MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid)
924{

Callers

nothing calls this directly

Calls 5

findMethod · 0.80
StateEnum · 0.70
GetBlockHashMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected