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

Method MaybePunishNodeForBlock

src/net_processing.cpp:1383–1431  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1381}
1382
1383bool PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state,
1384 bool via_compact_block, const std::string& message)
1385{
1386 switch (state.GetResult()) {
1387 case BlockValidationResult::BLOCK_RESULT_UNSET:
1388 break;
1389 // The node is providing invalid data:
1390 case BlockValidationResult::BLOCK_CONSENSUS:
1391 case BlockValidationResult::BLOCK_MUTATED:
1392 if (!via_compact_block) {
1393 Misbehaving(nodeid, 100, message);
1394 return true;
1395 }
1396 break;
1397 case BlockValidationResult::BLOCK_CACHED_INVALID:
1398 {
1399 LOCK(cs_main);
1400 CNodeState *node_state = State(nodeid);
1401 if (node_state == nullptr) {
1402 break;
1403 }
1404
1405 // Discourage outbound (but not inbound) peers if on an invalid chain.
1406 // Exempt HB compact block peers. Manual connections are always protected from discouragement.
1407 if (!via_compact_block && !node_state->m_is_inbound) {
1408 Misbehaving(nodeid, 100, message);
1409 return true;
1410 }
1411 break;
1412 }
1413 case BlockValidationResult::BLOCK_INVALID_HEADER:
1414 case BlockValidationResult::BLOCK_CHECKPOINT:
1415 case BlockValidationResult::BLOCK_INVALID_PREV:
1416 Misbehaving(nodeid, 100, message);
1417 return true;
1418 // Conflicting (but not necessarily invalid) data or different policy:
1419 case BlockValidationResult::BLOCK_MISSING_PREV:
1420 // TODO: Handle this much more gracefully (10 DoS points is super arbitrary)
1421 Misbehaving(nodeid, 10, message);
1422 return true;
1423 case BlockValidationResult::BLOCK_RECENT_CONSENSUS_CHANGE:
1424 case BlockValidationResult::BLOCK_TIME_FUTURE:
1425 break;
1426 }
1427 if (message != "") {
1428 LogPrint(BCLog::NET, "peer=%d: %s\n", nodeid, message);
1429 }
1430 return false;
1431}
1432
1433bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex* pindex)
1434{

Callers

nothing calls this directly

Calls 2

GetResultMethod · 0.80
StateEnum · 0.70

Tested by

no test coverage detected