mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
Merge pull request #5669
da29ecbConsensus: MOVEONLY: Move CValidationState from main consensus/validation (jtimon)27afcd8Consensus: Refactor: Decouple CValidationState from main::AbortNode() (Cory Fields)
This commit is contained in:
75
src/main.h
75
src/main.h
@@ -89,16 +89,6 @@ static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
|
||||
/** Maximum length of reject messages. */
|
||||
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
|
||||
|
||||
/** "reject" message codes */
|
||||
static const unsigned char REJECT_MALFORMED = 0x01;
|
||||
static const unsigned char REJECT_INVALID = 0x10;
|
||||
static const unsigned char REJECT_OBSOLETE = 0x11;
|
||||
static const unsigned char REJECT_DUPLICATE = 0x12;
|
||||
static const unsigned char REJECT_NONSTANDARD = 0x40;
|
||||
static const unsigned char REJECT_DUST = 0x41;
|
||||
static const unsigned char REJECT_INSUFFICIENTFEE = 0x42;
|
||||
static const unsigned char REJECT_CHECKPOINT = 0x43;
|
||||
|
||||
struct BlockHasher
|
||||
{
|
||||
size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); }
|
||||
@@ -230,8 +220,6 @@ void UnlinkPrunedFiles(std::set<int>& setFilesToPrune);
|
||||
|
||||
/** Create a new block index entry for a given block hash */
|
||||
CBlockIndex * InsertBlockIndex(uint256 hash);
|
||||
/** Abort with a message */
|
||||
bool AbortNode(const std::string &msg, const std::string &userMessage="");
|
||||
/** Get statistics from node state */
|
||||
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
|
||||
/** Increase a node's misbehavior score. */
|
||||
@@ -461,69 +449,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/** Capture information about block/transaction validation */
|
||||
class CValidationState {
|
||||
private:
|
||||
enum mode_state {
|
||||
MODE_VALID, //! everything ok
|
||||
MODE_INVALID, //! network rule violation (DoS value may be set)
|
||||
MODE_ERROR, //! run-time error
|
||||
} mode;
|
||||
int nDoS;
|
||||
std::string strRejectReason;
|
||||
unsigned char 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="",
|
||||
bool corruptionIn=false) {
|
||||
chRejectCode = chRejectCodeIn;
|
||||
strRejectReason = strRejectReasonIn;
|
||||
corruptionPossible = corruptionIn;
|
||||
if (mode == MODE_ERROR)
|
||||
return ret;
|
||||
nDoS += level;
|
||||
mode = MODE_INVALID;
|
||||
return ret;
|
||||
}
|
||||
bool Invalid(bool ret = false,
|
||||
unsigned char _chRejectCode=0, std::string _strRejectReason="") {
|
||||
return DoS(0, ret, _chRejectCode, _strRejectReason);
|
||||
}
|
||||
bool Error(std::string strRejectReasonIn="") {
|
||||
if (mode == MODE_VALID)
|
||||
strRejectReason = strRejectReasonIn;
|
||||
mode = MODE_ERROR;
|
||||
return false;
|
||||
}
|
||||
bool Abort(const std::string &msg) {
|
||||
AbortNode(msg);
|
||||
return Error(msg);
|
||||
}
|
||||
bool IsValid() const {
|
||||
return mode == MODE_VALID;
|
||||
}
|
||||
bool IsInvalid() const {
|
||||
return mode == MODE_INVALID;
|
||||
}
|
||||
bool IsError() const {
|
||||
return mode == MODE_ERROR;
|
||||
}
|
||||
bool IsInvalid(int &nDoSOut) const {
|
||||
if (IsInvalid()) {
|
||||
nDoSOut = nDoS;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool CorruptionPossible() const {
|
||||
return corruptionPossible;
|
||||
}
|
||||
unsigned char GetRejectCode() const { return chRejectCode; }
|
||||
std::string GetRejectReason() const { return strRejectReason; }
|
||||
};
|
||||
|
||||
/** RAII wrapper for VerifyDB: Verify consistency of the block and coin databases */
|
||||
class CVerifyDB {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user