Skip to content

Commit

Permalink
[net processing] Move MaybePunishNodeForBlock into PeerManager
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewbery committed Sep 7, 2020
1 parent d777835 commit b70cd89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,17 +1132,9 @@ void Misbehaving(const NodeId pnode, const int howmuch, const std::string& messa
}
}

/**
* Potentially mark a node discouraged based on the contents of a BlockValidationState object
*
* @param[in] via_compact_block this bool is passed in because net_processing should
* punish peers differently depending on whether the data was provided in a compact
* block message or not. If the compact block had a valid header, but contained invalid
* txs, the peer should not be punished. See BIP 152.
*
* @return Returns true if the peer was punished (probably disconnected)
*/
static bool MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state, bool via_compact_block, const std::string& message = "") {
bool PeerManager::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state,
bool via_compact_block, const std::string& message)
{
switch (state.GetResult()) {
case BlockValidationResult::BLOCK_RESULT_UNSET:
break;
Expand Down
14 changes: 14 additions & 0 deletions src/net_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sync.h>
#include <validationinterface.h>

class BlockValidationState;
class CBlockHeader;
class CChainParams;
class CTxMemPool;
Expand Down Expand Up @@ -84,6 +85,19 @@ class PeerManager final : public CValidationInterface, public NetEventsInterface
const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc);

private:
/**
* Potentially mark a node discouraged based on the contents of a BlockValidationState object
*
* @param[in] via_compact_block this bool is passed in because net_processing should
* punish peers differently depending on whether the data was provided in a compact
* block message or not. If the compact block had a valid header, but contained invalid
* txs, the peer should not be punished. See BIP 152.
*
* @return Returns true if the peer was punished (probably disconnected)
*/
bool MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state,
bool via_compact_block, const std::string& message = "");

/** Maybe disconnect a peer and discourage future connections from its address.
*
* @param[in] pnode The node to check.
Expand Down

0 comments on commit b70cd89

Please sign in to comment.