Changeset View
Changeset View
Standalone View
Standalone View
src/consensus/validation.h
| Show All 16 Lines | |||||
| static const uint8_t REJECT_DUST = 0x41; | static const uint8_t REJECT_DUST = 0x41; | ||||
| static const uint8_t REJECT_INSUFFICIENTFEE = 0x42; | static const uint8_t REJECT_INSUFFICIENTFEE = 0x42; | ||||
| static const uint8_t REJECT_CHECKPOINT = 0x43; | static const uint8_t REJECT_CHECKPOINT = 0x43; | ||||
| /** Capture information about block/transaction validation */ | /** Capture information about block/transaction validation */ | ||||
| class CValidationState { | class CValidationState { | ||||
| private: | private: | ||||
| enum mode_state { | enum mode_state { | ||||
| MODE_VALID, //!< everything ok | MODE_VALID, //!< everything ok | ||||
| MODE_EXCESSIVE, //!< network soft rule violation | |||||
| MODE_INVALID, //!< network rule violation (DoS value may be set) | MODE_INVALID, //!< network rule violation (DoS value may be set) | ||||
| MODE_ERROR, //!< run-time error | MODE_ERROR, //!< run-time error | ||||
| } mode; | } mode; | ||||
| int nDoS; | int nDoS; | ||||
| std::string strRejectReason; | std::string strRejectReason; | ||||
| unsigned int chRejectCode; | unsigned int chRejectCode; | ||||
| bool corruptionPossible; | bool corruptionPossible; | ||||
| std::string strDebugMessage; | std::string strDebugMessage; | ||||
| public: | public: | ||||
| Show All 12 Lines | bool DoS(int level, bool ret = false, unsigned int chRejectCodeIn = 0, | ||||
| if (mode == MODE_ERROR) { | if (mode == MODE_ERROR) { | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| nDoS += level; | nDoS += level; | ||||
| mode = MODE_INVALID; | mode = MODE_INVALID; | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| // It works like the DoS function but setting the mode as EXCESSIVE | |||||
deadalnix: Dos has all these parameters because down the road this is the one that get called. Excessive… | |||||
| bool Excessive(int level, bool ret = false, unsigned int chRejectCodeIn = 0, | |||||
| const std::string &strRejectReasonIn = "", | |||||
| bool corruptionIn = false, | |||||
| const std::string &strDebugMessageIn = "") { | |||||
| ret = DoS(level, ret, chRejectCodeIn, strRejectReasonIn, corruptionIn, | |||||
| strDebugMessageIn); | |||||
| if (mode == MODE_ERROR) { | |||||
| return ret; | |||||
| } | |||||
| mode = MODE_EXCESSIVE; | |||||
| return ret; | |||||
| } | |||||
| bool Invalid(bool ret = false, unsigned int _chRejectCode = 0, | bool Invalid(bool ret = false, unsigned int _chRejectCode = 0, | ||||
| const std::string &_strRejectReason = "", | const std::string &_strRejectReason = "", | ||||
| const std::string &_strDebugMessage = "") { | const std::string &_strDebugMessage = "") { | ||||
| return DoS(0, ret, _chRejectCode, _strRejectReason, false, | return DoS(0, ret, _chRejectCode, _strRejectReason, false, | ||||
| _strDebugMessage); | _strDebugMessage); | ||||
| } | } | ||||
| bool Error(const std::string &strRejectReasonIn) { | bool Error(const std::string &strRejectReasonIn) { | ||||
| if (mode == MODE_VALID) { | if (mode == MODE_VALID) { | ||||
| strRejectReason = strRejectReasonIn; | strRejectReason = strRejectReasonIn; | ||||
| } | } | ||||
| mode = MODE_ERROR; | mode = MODE_ERROR; | ||||
| return false; | return false; | ||||
| } | } | ||||
| bool IsValid() const { return mode == MODE_VALID; } | bool IsValid() const { return mode == MODE_VALID; } | ||||
| bool IsNotValid() const { | |||||
| return ((mode == MODE_EXCESSIVE) || (mode == MODE_INVALID)); | |||||
| } | |||||
| bool IsExcessive() const { return mode == MODE_EXCESSIVE; } | |||||
| bool IsInvalid() const { return mode == MODE_INVALID; } | bool IsInvalid() const { return mode == MODE_INVALID; } | ||||
| bool IsError() const { return mode == MODE_ERROR; } | bool IsError() const { return mode == MODE_ERROR; } | ||||
| bool IsInvalid(int &nDoSOut) const { | bool IsInvalid(int &nDoSOut) const { | ||||
| if (IsInvalid()) { | if (IsInvalid()) { | ||||
| nDoSOut = nDoS; | nDoSOut = nDoS; | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| bool IsNotValid(int &nDoSOut) const { | |||||
| if (IsNotValid()) { | |||||
| nDoSOut = nDoS; | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| bool CorruptionPossible() const { return corruptionPossible; } | bool CorruptionPossible() const { return corruptionPossible; } | ||||
| void SetCorruptionPossible() { corruptionPossible = true; } | void SetCorruptionPossible() { corruptionPossible = true; } | ||||
| unsigned int GetRejectCode() const { return chRejectCode; } | unsigned int GetRejectCode() const { return chRejectCode; } | ||||
| std::string GetRejectReason() const { return strRejectReason; } | std::string GetRejectReason() const { return strRejectReason; } | ||||
| std::string GetDebugMessage() const { return strDebugMessage; } | std::string GetDebugMessage() const { return strDebugMessage; } | ||||
| }; | }; | ||||
| #endif // BITCOIN_CONSENSUS_VALIDATION_H | #endif // BITCOIN_CONSENSUS_VALIDATION_H | ||||
Dos has all these parameters because down the road this is the one that get called. Excessive do not need to conform the the API. For instance, it doesn't make sense to tag a block excessive because of corruption.