Skip to content

Commit a0625b8

Browse files
committed
Merge pull request #5913
5922b67 Add assertion and cast before sending reject code (Wladimir J. van der Laan) a651403 Add absurdly high fee message to validation state (for RPC propagation) (Shaul Kfir)
2 parents c384800 + 5922b67 commit a0625b8

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/consensus/validation.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class CValidationState {
2828
} mode;
2929
int nDoS;
3030
std::string strRejectReason;
31-
unsigned char chRejectCode;
31+
unsigned int chRejectCode;
3232
bool corruptionPossible;
3333
public:
3434
CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false) {}
3535
bool DoS(int level, bool ret = false,
36-
unsigned char chRejectCodeIn=0, std::string strRejectReasonIn="",
36+
unsigned int chRejectCodeIn=0, std::string strRejectReasonIn="",
3737
bool corruptionIn=false) {
3838
chRejectCode = chRejectCodeIn;
3939
strRejectReason = strRejectReasonIn;
@@ -45,7 +45,7 @@ class CValidationState {
4545
return ret;
4646
}
4747
bool Invalid(bool ret = false,
48-
unsigned char _chRejectCode=0, std::string _strRejectReason="") {
48+
unsigned int _chRejectCode=0, std::string _strRejectReason="") {
4949
return DoS(0, ret, _chRejectCode, _strRejectReason);
5050
}
5151
bool Error(const std::string& strRejectReasonIn) {
@@ -73,7 +73,7 @@ class CValidationState {
7373
bool CorruptionPossible() const {
7474
return corruptionPossible;
7575
}
76-
unsigned char GetRejectCode() const { return chRejectCode; }
76+
unsigned int GetRejectCode() const { return chRejectCode; }
7777
std::string GetRejectReason() const { return strRejectReason; }
7878
};
7979

src/main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -927,9 +927,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
927927
}
928928

929929
if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000)
930-
return error("AcceptToMemoryPool: absurdly high fees %s, %d > %d",
931-
hash.ToString(),
932-
nFees, ::minRelayTxFee.GetFee(nSize) * 10000);
930+
return state.Invalid(error("AcceptToMemoryPool: absurdly high fees %s, %d > %d",
931+
hash.ToString(),
932+
nFees, ::minRelayTxFee.GetFee(nSize) * 10000),
933+
REJECT_HIGHFEE, "absurdly-high-fee");
933934

934935
// Check against previous transactions
935936
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
@@ -1238,7 +1239,8 @@ void static InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state
12381239
if (state.IsInvalid(nDoS)) {
12391240
std::map<uint256, NodeId>::iterator it = mapBlockSource.find(pindex->GetBlockHash());
12401241
if (it != mapBlockSource.end() && State(it->second)) {
1241-
CBlockReject reject = {state.GetRejectCode(), state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), pindex->GetBlockHash()};
1242+
assert(state.GetRejectCode() < 0x100);
1243+
CBlockReject reject = {(unsigned char)state.GetRejectCode(), state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), pindex->GetBlockHash()};
12421244
State(it->second)->rejects.push_back(reject);
12431245
if (nDoS > 0)
12441246
Misbehaving(it->second, nDoS);

src/main.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,4 +455,7 @@ extern CBlockTreeDB *pblocktree;
455455
*/
456456
int GetSpendHeight(const CCoinsViewCache& inputs);
457457

458+
/** local "reject" message codes for RPC which can not be triggered by p2p trasactions */
459+
static const unsigned int REJECT_HIGHFEE = 0x100;
460+
458461
#endif // BITCOIN_MAIN_H

0 commit comments

Comments
 (0)