MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / BlockChecked

Method BlockChecked

src/net_processing.cpp:988–1019  ·  view source on GitHub ↗

* Handle invalid block rejection and consequent peer banning, maintain which * peers announce compact blocks. */

Source from the content-addressed store, hash-verified

986 * peers announce compact blocks.
987 */
988void PeerLogicValidation::BlockChecked(const CBlock& block, const CValidationState& state) {
989 LOCK(cs_main);
990
991 const uint256 hash(block.GetHash());
992 std::map<uint256, std::pair<NodeId, bool>>::iterator it = mapBlockSource.find(hash);
993
994 int nDoS = 0;
995 if (state.IsInvalid(nDoS)) {
996 // Don't send reject message with code 0 or an internal reject code.
997 if (it != mapBlockSource.end() && State(it->second.first) && state.GetRejectCode() > 0 && state.GetRejectCode() < REJECT_INTERNAL) {
998 CBlockReject reject = {(unsigned char)state.GetRejectCode(), state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), hash};
999 State(it->second.first)->rejects.push_back(reject);
1000 if (nDoS > 0 && it->second.second)
1001 Misbehaving(it->second.first, nDoS);
1002 }
1003 }
1004 // Check that:
1005 // 1. The block is valid
1006 // 2. We're not in initial block download
1007 // 3. This is currently the best block we're aware of. We haven't updated
1008 // the tip yet so we have no way to check this directly here. Instead we
1009 // just check that there are currently no other blocks in flight.
1010 else if (state.IsValid() &&
1011 !IsInitialBlockDownload() &&
1012 mapBlocksInFlight.count(hash) == mapBlocksInFlight.size()) {
1013 if (it != mapBlockSource.end()) {
1014 MaybeSetPeerAsAnnouncingHeaderAndIDs(it->second.first, connman);
1015 }
1016 }
1017 if (it != mapBlockSource.end())
1018 mapBlockSource.erase(it);
1019}
1020
1021//////////////////////////////////////////////////////////////////////////////
1022//

Callers 2

ConnectTipMethod · 0.45
ProcessNewBlockFunction · 0.45

Calls 14

IsInitialBlockDownloadFunction · 0.85
IsInvalidMethod · 0.80
GetRejectCodeMethod · 0.80
GetRejectReasonMethod · 0.80
StateClass · 0.50
GetHashMethod · 0.45
findMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
IsValidMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected