mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-29 18:20:58 +02:00
[refactor] Drop redundant nDoS, corruptionPossible, SetCorruptionPossible
Co-authored-by: Anthony Towns <aj@erisian.com.au>
This commit is contained in:
committed by
Suhas Daftuar
parent
34477ccd39
commit
c8b0d22698
@ -75,25 +75,20 @@ private:
|
|||||||
MODE_ERROR, //!< run-time error
|
MODE_ERROR, //!< run-time error
|
||||||
} mode;
|
} mode;
|
||||||
ValidationInvalidReason m_reason;
|
ValidationInvalidReason m_reason;
|
||||||
int nDoS;
|
|
||||||
std::string strRejectReason;
|
std::string strRejectReason;
|
||||||
unsigned int chRejectCode;
|
unsigned int chRejectCode;
|
||||||
bool corruptionPossible;
|
|
||||||
std::string strDebugMessage;
|
std::string strDebugMessage;
|
||||||
public:
|
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,
|
bool DoS(int level, ValidationInvalidReason reasonIn, bool ret = false,
|
||||||
unsigned int chRejectCodeIn=0, const std::string &strRejectReasonIn="",
|
unsigned int chRejectCodeIn=0, const std::string &strRejectReasonIn="",
|
||||||
bool corruptionIn=false,
|
bool corruptionPossibleIn=false,
|
||||||
const std::string &strDebugMessageIn="") {
|
const std::string &strDebugMessageIn="") {
|
||||||
m_reason = reasonIn;
|
m_reason = reasonIn;
|
||||||
chRejectCode = chRejectCodeIn;
|
chRejectCode = chRejectCodeIn;
|
||||||
strRejectReason = strRejectReasonIn;
|
strRejectReason = strRejectReasonIn;
|
||||||
corruptionPossible = corruptionIn;
|
|
||||||
strDebugMessage = strDebugMessageIn;
|
strDebugMessage = strDebugMessageIn;
|
||||||
nDoS += level;
|
assert(corruptionPossibleIn == CorruptionPossible());
|
||||||
assert(nDoS == GetDoSForReason());
|
|
||||||
assert(corruptionPossible == (m_reason == ValidationInvalidReason::BLOCK_MUTATED || m_reason == ValidationInvalidReason::TX_WITNESS_MUTATED));
|
|
||||||
if (mode == MODE_ERROR)
|
if (mode == MODE_ERROR)
|
||||||
return ret;
|
return ret;
|
||||||
mode = MODE_INVALID;
|
mode = MODE_INVALID;
|
||||||
@ -120,15 +115,9 @@ public:
|
|||||||
return mode == MODE_ERROR;
|
return mode == MODE_ERROR;
|
||||||
}
|
}
|
||||||
bool CorruptionPossible() const {
|
bool CorruptionPossible() const {
|
||||||
assert(corruptionPossible == (m_reason == ValidationInvalidReason::BLOCK_MUTATED || m_reason == ValidationInvalidReason::TX_WITNESS_MUTATED));
|
return m_reason == ValidationInvalidReason::BLOCK_MUTATED || m_reason == ValidationInvalidReason::TX_WITNESS_MUTATED;
|
||||||
return corruptionPossible;
|
|
||||||
}
|
}
|
||||||
void SetCorruptionPossible() {
|
int GetDoS() const {
|
||||||
corruptionPossible = true;
|
|
||||||
assert(corruptionPossible == (m_reason == ValidationInvalidReason::BLOCK_MUTATED || m_reason == ValidationInvalidReason::TX_WITNESS_MUTATED));
|
|
||||||
}
|
|
||||||
int GetDoS(void) const { return nDoS; }
|
|
||||||
int GetDoSForReason() const {
|
|
||||||
switch (m_reason) {
|
switch (m_reason) {
|
||||||
case ValidationInvalidReason::NONE:
|
case ValidationInvalidReason::NONE:
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -961,7 +961,6 @@ void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIV
|
|||||||
|
|
||||||
static bool TxRelayMayResultInDisconnect(const CValidationState& state)
|
static bool TxRelayMayResultInDisconnect(const CValidationState& state)
|
||||||
{
|
{
|
||||||
assert(state.GetDoS() == state.GetDoSForReason());
|
|
||||||
return (state.GetDoS() > 0);
|
return (state.GetDoS() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -976,7 +975,6 @@ static bool TxRelayMayResultInDisconnect(const CValidationState& state)
|
|||||||
* txs, the peer should not be punished. See BIP 152.
|
* 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 = "") {
|
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();
|
int nDoS = state.GetDoS();
|
||||||
if (nDoS > 0 && !via_compact_block) {
|
if (nDoS > 0 && !via_compact_block) {
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
Reference in New Issue
Block a user