From a651403e09ccc9ac0a3322e880d6543dd51a14bd Mon Sep 17 00:00:00 2001 From: Shaul Kfir Date: Mon, 16 Mar 2015 21:36:43 -0400 Subject: Add absurdly high fee message to validation state (for RPC propagation) --- src/consensus/validation.h | 8 ++++---- src/main.cpp | 7 ++++--- src/main.h | 3 +++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/consensus/validation.h b/src/consensus/validation.h index a97d983a31..719e090a42 100644 --- a/src/consensus/validation.h +++ b/src/consensus/validation.h @@ -28,12 +28,12 @@ private: } mode; int nDoS; std::string strRejectReason; - unsigned char chRejectCode; + unsigned int chRejectCode; bool corruptionPossible; public: CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false) {} bool DoS(int level, bool ret = false, - unsigned char chRejectCodeIn=0, std::string strRejectReasonIn="", + unsigned int chRejectCodeIn=0, std::string strRejectReasonIn="", bool corruptionIn=false) { chRejectCode = chRejectCodeIn; strRejectReason = strRejectReasonIn; @@ -45,7 +45,7 @@ public: return ret; } bool Invalid(bool ret = false, - unsigned char _chRejectCode=0, std::string _strRejectReason="") { + unsigned int _chRejectCode=0, std::string _strRejectReason="") { return DoS(0, ret, _chRejectCode, _strRejectReason); } bool Error(const std::string& strRejectReasonIn) { @@ -73,7 +73,7 @@ public: bool CorruptionPossible() const { return corruptionPossible; } - unsigned char GetRejectCode() const { return chRejectCode; } + unsigned int GetRejectCode() const { return chRejectCode; } std::string GetRejectReason() const { return strRejectReason; } }; diff --git a/src/main.cpp b/src/main.cpp index 6c4cfe75aa..f67f1fd0d7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1031,9 +1031,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000) - return error("AcceptToMemoryPool: absurdly high fees %s, %d > %d", - hash.ToString(), - nFees, ::minRelayTxFee.GetFee(nSize) * 10000); + return state.Invalid(error("AcceptToMemoryPool: absurdly high fees %s, %d > %d", + hash.ToString(), + nFees, ::minRelayTxFee.GetFee(nSize) * 10000), + REJECT_HIGHFEE, "absurdly-high-fee"); // Check against previous transactions // This is done last to help prevent CPU exhaustion denial-of-service attacks. diff --git a/src/main.h b/src/main.h index 4e2efaada0..e11d5c857d 100644 --- a/src/main.h +++ b/src/main.h @@ -497,4 +497,7 @@ extern CBlockTreeDB *pblocktree; */ int GetSpendHeight(const CCoinsViewCache& inputs); +/** local "reject" message codes for RPC which can not be triggered by p2p trasactions */ +static const unsigned int REJECT_HIGHFEE = 0x100; + #endif // BITCOIN_MAIN_H -- cgit v1.2.3 From 5922b6774e352e802ca9a347cc224cfebf1a6a7d Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 5 Aug 2015 19:02:19 +0200 Subject: Add assertion and cast before sending reject code This gets rid of a warning. Add an assertion to make sure that the reject code is in the correct range for the network protocol (if it is outside the range it must be a bug) --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f67f1fd0d7..4bf5883692 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1343,7 +1343,8 @@ void static InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state if (state.IsInvalid(nDoS)) { std::map::iterator it = mapBlockSource.find(pindex->GetBlockHash()); if (it != mapBlockSource.end() && State(it->second)) { - CBlockReject reject = {state.GetRejectCode(), state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), pindex->GetBlockHash()}; + assert(state.GetRejectCode() < 0x100); + CBlockReject reject = {(unsigned char)state.GetRejectCode(), state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), pindex->GetBlockHash()}; State(it->second)->rejects.push_back(reject); if (nDoS > 0) Misbehaving(it->second, nDoS); -- cgit v1.2.3