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)
This commit is contained in:
commit
a0625b8085
3 changed files with 13 additions and 8 deletions
|
@ -28,12 +28,12 @@ private:
|
||||||
} mode;
|
} mode;
|
||||||
int nDoS;
|
int nDoS;
|
||||||
std::string strRejectReason;
|
std::string strRejectReason;
|
||||||
unsigned char chRejectCode;
|
unsigned int chRejectCode;
|
||||||
bool corruptionPossible;
|
bool corruptionPossible;
|
||||||
public:
|
public:
|
||||||
CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false) {}
|
CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false) {}
|
||||||
bool DoS(int level, bool ret = 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) {
|
bool corruptionIn=false) {
|
||||||
chRejectCode = chRejectCodeIn;
|
chRejectCode = chRejectCodeIn;
|
||||||
strRejectReason = strRejectReasonIn;
|
strRejectReason = strRejectReasonIn;
|
||||||
|
@ -45,7 +45,7 @@ public:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
bool Invalid(bool ret = false,
|
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);
|
return DoS(0, ret, _chRejectCode, _strRejectReason);
|
||||||
}
|
}
|
||||||
bool Error(const std::string& strRejectReasonIn) {
|
bool Error(const std::string& strRejectReasonIn) {
|
||||||
|
@ -73,7 +73,7 @@ public:
|
||||||
bool CorruptionPossible() const {
|
bool CorruptionPossible() const {
|
||||||
return corruptionPossible;
|
return corruptionPossible;
|
||||||
}
|
}
|
||||||
unsigned char GetRejectCode() const { return chRejectCode; }
|
unsigned int GetRejectCode() const { return chRejectCode; }
|
||||||
std::string GetRejectReason() const { return strRejectReason; }
|
std::string GetRejectReason() const { return strRejectReason; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
10
src/main.cpp
10
src/main.cpp
|
@ -927,9 +927,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000)
|
if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000)
|
||||||
return error("AcceptToMemoryPool: absurdly high fees %s, %d > %d",
|
return state.Invalid(error("AcceptToMemoryPool: absurdly high fees %s, %d > %d",
|
||||||
hash.ToString(),
|
hash.ToString(),
|
||||||
nFees, ::minRelayTxFee.GetFee(nSize) * 10000);
|
nFees, ::minRelayTxFee.GetFee(nSize) * 10000),
|
||||||
|
REJECT_HIGHFEE, "absurdly-high-fee");
|
||||||
|
|
||||||
// Check against previous transactions
|
// Check against previous transactions
|
||||||
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
|
// 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
|
||||||
if (state.IsInvalid(nDoS)) {
|
if (state.IsInvalid(nDoS)) {
|
||||||
std::map<uint256, NodeId>::iterator it = mapBlockSource.find(pindex->GetBlockHash());
|
std::map<uint256, NodeId>::iterator it = mapBlockSource.find(pindex->GetBlockHash());
|
||||||
if (it != mapBlockSource.end() && State(it->second)) {
|
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);
|
State(it->second)->rejects.push_back(reject);
|
||||||
if (nDoS > 0)
|
if (nDoS > 0)
|
||||||
Misbehaving(it->second, nDoS);
|
Misbehaving(it->second, nDoS);
|
||||||
|
|
|
@ -455,4 +455,7 @@ extern CBlockTreeDB *pblocktree;
|
||||||
*/
|
*/
|
||||||
int GetSpendHeight(const CCoinsViewCache& inputs);
|
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
|
#endif // BITCOIN_MAIN_H
|
||||||
|
|
Loading…
Reference in a new issue