Skip to content

Commit fbf44e6

Browse files
committed
Add debug message to CValidationState for optional extra information
Add a field `strDebugMessage` which can be passed to DoS or Invalid, and queried using GetDebugMessage() to add extra troubleshooting information to the validation state.
1 parent 149f96c commit fbf44e6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/consensus/validation.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,27 @@ class CValidationState {
3030
std::string strRejectReason;
3131
unsigned int chRejectCode;
3232
bool corruptionPossible;
33+
std::string strDebugMessage;
3334
public:
3435
CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false) {}
3536
bool DoS(int level, bool ret = false,
36-
unsigned int chRejectCodeIn=0, std::string strRejectReasonIn="",
37-
bool corruptionIn=false) {
37+
unsigned int chRejectCodeIn=0, const std::string &strRejectReasonIn="",
38+
bool corruptionIn=false,
39+
const std::string &strDebugMessageIn="") {
3840
chRejectCode = chRejectCodeIn;
3941
strRejectReason = strRejectReasonIn;
4042
corruptionPossible = corruptionIn;
43+
strDebugMessage = strDebugMessageIn;
4144
if (mode == MODE_ERROR)
4245
return ret;
4346
nDoS += level;
4447
mode = MODE_INVALID;
4548
return ret;
4649
}
4750
bool Invalid(bool ret = false,
48-
unsigned int _chRejectCode=0, std::string _strRejectReason="") {
49-
return DoS(0, ret, _chRejectCode, _strRejectReason);
51+
unsigned int _chRejectCode=0, const std::string &_strRejectReason="",
52+
const std::string &_strDebugMessage="") {
53+
return DoS(0, ret, _chRejectCode, _strRejectReason, false, _strDebugMessage);
5054
}
5155
bool Error(const std::string& strRejectReasonIn) {
5256
if (mode == MODE_VALID)
@@ -75,6 +79,7 @@ class CValidationState {
7579
}
7680
unsigned int GetRejectCode() const { return chRejectCode; }
7781
std::string GetRejectReason() const { return strRejectReason; }
82+
std::string GetDebugMessage() const { return strDebugMessage; }
7883
};
7984

8085
#endif // BITCOIN_CONSENSUS_VALIDATION_H

0 commit comments

Comments
 (0)