diff options
author | Matt Corallo <git@bluematt.me> | 2019-01-18 12:58:41 +1000 |
---|---|---|
committer | Suhas Daftuar <sdaftuar@gmail.com> | 2019-05-02 15:10:32 -0400 |
commit | c8b0d22698385f91215ce8145631e3d5826dc977 (patch) | |
tree | f3ff70231f17bc4a7d232a7084825cb0b91efe8d | |
parent | 34477ccd39a8d4bfa8ad612f22d5a46291922185 (diff) |
[refactor] Drop redundant nDoS, corruptionPossible, SetCorruptionPossible
Co-authored-by: Anthony Towns <aj@erisian.com.au>
-rw-r--r-- | src/consensus/validation.h | 21 | ||||
-rw-r--r-- | src/net_processing.cpp | 2 |
2 files changed, 5 insertions, 18 deletions
diff --git a/src/consensus/validation.h b/src/consensus/validation.h index 787b171eea..a18739135f 100644 --- a/src/consensus/validation.h +++ b/src/consensus/validation.h @@ -75,25 +75,20 @@ private: MODE_ERROR, //!< run-time error } mode; ValidationInvalidReason m_reason; - int nDoS; std::string strRejectReason; unsigned int chRejectCode; - bool corruptionPossible; std::string strDebugMessage; public: - CValidationState() : mode(MODE_VALID), m_reason(ValidationInvalidReason::NONE), nDoS(0), chRejectCode(0), corruptionPossible(false) {} + CValidationState() : mode(MODE_VALID), m_reason(ValidationInvalidReason::NONE), chRejectCode(0) {} bool DoS(int level, ValidationInvalidReason reasonIn, bool ret = false, unsigned int chRejectCodeIn=0, const std::string &strRejectReasonIn="", - bool corruptionIn=false, + bool corruptionPossibleIn=false, const std::string &strDebugMessageIn="") { m_reason = reasonIn; chRejectCode = chRejectCodeIn; strRejectReason = strRejectReasonIn; - corruptionPossible = corruptionIn; strDebugMessage = strDebugMessageIn; - nDoS += level; - assert(nDoS == GetDoSForReason()); - assert(corruptionPossible == (m_reason == ValidationInvalidReason::BLOCK_MUTATED || m_reason == ValidationInvalidReason::TX_WITNESS_MUTATED)); + assert(corruptionPossibleIn == CorruptionPossible()); if (mode == MODE_ERROR) return ret; mode = MODE_INVALID; @@ -120,15 +115,9 @@ public: return mode == MODE_ERROR; } bool CorruptionPossible() const { - assert(corruptionPossible == (m_reason == ValidationInvalidReason::BLOCK_MUTATED || m_reason == ValidationInvalidReason::TX_WITNESS_MUTATED)); - return corruptionPossible; + return m_reason == ValidationInvalidReason::BLOCK_MUTATED || m_reason == ValidationInvalidReason::TX_WITNESS_MUTATED; } - void SetCorruptionPossible() { - corruptionPossible = true; - assert(corruptionPossible == (m_reason == ValidationInvalidReason::BLOCK_MUTATED || m_reason == ValidationInvalidReason::TX_WITNESS_MUTATED)); - } - int GetDoS(void) const { return nDoS; } - int GetDoSForReason() const { + int GetDoS() const { switch (m_reason) { case ValidationInvalidReason::NONE: return 0; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 489ffcdc66..a416093db1 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -961,7 +961,6 @@ void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIV static bool TxRelayMayResultInDisconnect(const CValidationState& state) { - assert(state.GetDoS() == state.GetDoSForReason()); return (state.GetDoS() > 0); } @@ -976,7 +975,6 @@ static bool TxRelayMayResultInDisconnect(const CValidationState& state) * txs, the peer should not be punished. See BIP 152. */ static bool MaybePunishNode(NodeId nodeid, const CValidationState& state, bool via_compact_block, const std::string& message = "") { - assert(state.GetDoS() == state.GetDoSForReason()); int nDoS = state.GetDoS(); if (nDoS > 0 && !via_compact_block) { LOCK(cs_main); |