diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -6,7 +6,8 @@ #include #include -#include // For DecodeSecret +#include // For DecodeSecret +#include // For Misbehaving #include #include #include @@ -270,7 +271,8 @@ auto w = queries.getWriteView(); auto it = w->find(std::make_tuple(nodeid, response.getRound())); if (it == w.end()) { - // NB: The request may be old, so we don't increase banscore. + LOCK(cs_main); + Misbehaving(nodeid, 2, "unexpcted-ava-response"); return false; } @@ -282,15 +284,15 @@ const std::vector &votes = response.GetVotes(); size_t size = invs.size(); if (votes.size() != size) { - // TODO: increase banscore for inconsistent response. - // NB: This isn't timeout but actually node misbehaving. + LOCK(cs_main); + Misbehaving(nodeid, 100, "invalid-ava-response-size"); return false; } for (size_t i = 0; i < size; i++) { if (invs[i].hash != votes[i].GetHash()) { - // TODO: increase banscore for inconsistent response. - // NB: This isn't timeout but actually node misbehaving. + LOCK(cs_main); + Misbehaving(nodeid, 100, "invalid-ava-response-content"); return false; } } diff --git a/src/net_processing.h b/src/net_processing.h --- a/src/net_processing.h +++ b/src/net_processing.h @@ -127,7 +127,8 @@ /** Get statistics from node state */ bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats); /** Increase a node's misbehavior score. */ -void Misbehaving(NodeId nodeid, int howmuch, const std::string &reason = ""); +void Misbehaving(NodeId nodeid, int howmuch, const std::string &reason = "") + EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** Relay transaction to every node */ void RelayTransaction(const TxId &txid, const CConnman &connman); diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1166,8 +1166,8 @@ /** * Mark a misbehaving peer to be banned depending upon the value of `-banscore`. */ -void Misbehaving(NodeId pnode, int howmuch, const std::string &reason) - EXCLUSIVE_LOCKS_REQUIRED(cs_main) { +void Misbehaving(NodeId pnode, int howmuch, const std::string &reason) { + AssertLockHeld(cs_main); if (howmuch == 0) { return; } @@ -3882,8 +3882,6 @@ std::vector updates; if (!g_avalanche->registerVotes(pfrom.GetId(), response, updates)) { - LOCK(cs_main); - Misbehaving(pfrom, 100, "invalid-ava-response-content"); return true; } diff --git a/test/lint/lint-circular-dependencies.sh b/test/lint/lint-circular-dependencies.sh --- a/test/lint/lint-circular-dependencies.sh +++ b/test/lint/lint-circular-dependencies.sh @@ -27,6 +27,7 @@ "wallet/rpcwallet -> wallet/wallet -> wallet/rpcwallet" "wallet/wallet -> wallet/walletdb -> wallet/wallet" "avalanche/processor -> validation -> avalanche/processor" + "avalanche/processor -> net_processing -> avalanche/processor" "chainparams -> protocol -> chainparams" "chainparamsbase -> util/system -> chainparamsbase" "minerfund -> validation -> minerfund"