Bitcoin ABC  0.23.3
P2P Digital Currency
validation.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_CONSENSUS_VALIDATION_H
7 #define BITCOIN_CONSENSUS_VALIDATION_H
8 
9 #include <cassert>
10 #include <string>
11 
16 enum class TxValidationResult {
18  TX_RESULT_UNSET = 0,
41 };
42 
79 };
80 
86 template <typename Result> class ValidationState {
87 private:
88  enum mode_state {
92  } m_mode{MODE_VALID};
93  Result m_result{};
94  std::string m_reject_reason;
95  std::string m_debug_message;
96 
97 public:
98  bool Invalid(Result result, const std::string &reject_reason = "",
99  const std::string &debug_message = "") {
100  m_result = result;
101  m_reject_reason = reject_reason;
102  m_debug_message = debug_message;
103  if (m_mode != MODE_ERROR) {
104  m_mode = MODE_INVALID;
105  }
106  return false;
107  }
108 
109  bool Error(const std::string &reject_reason) {
110  if (m_mode == MODE_VALID) {
111  m_reject_reason = reject_reason;
112  }
113  m_mode = MODE_ERROR;
114  return false;
115  }
116  bool IsValid() const { return m_mode == MODE_VALID; }
117  bool IsInvalid() const { return m_mode == MODE_INVALID; }
118  bool IsError() const { return m_mode == MODE_ERROR; }
119  Result GetResult() const { return m_result; }
120  std::string GetRejectReason() const { return m_reject_reason; }
121  std::string GetDebugMessage() const { return m_debug_message; }
122  std::string ToString() const {
123  if (IsValid()) {
124  return "Valid";
125  }
126 
127  if (!m_debug_message.empty()) {
128  return m_reject_reason + ", " + m_debug_message;
129  }
130 
131  return m_reject_reason;
132  }
133 };
134 
135 class TxValidationState : public ValidationState<TxValidationResult> {};
136 class BlockValidationState : public ValidationState<BlockValidationResult> {};
137 
138 #endif // BITCOIN_CONSENSUS_VALIDATION_H
invalid by consensus rules
bool Error(const std::string &reject_reason)
Definition: validation.h:109
std::string GetDebugMessage() const
Definition: validation.h:121
Template for capturing information about block/transaction validation.
Definition: validation.h:86
We don&#39;t have the previous block the checked one is built on.
invalid proof of work or time too old
BlockValidationResult
A "reason" why a block was invalid, suitable for determining whether the provider of the block should...
Definition: validation.h:49
transaction was missing some of its inputs
block finalization problems
violated mempool&#39;s fee/size/descendant/etc limits
transaction spends a coinbase too early, or violates locktime/sequence locks
initial value. Tx has not yet been rejected
bool IsValid() const
Definition: validation.h:116
initial value. Block has not yet been rejected
Invalid by a recent change to consensus rules.
bool Invalid(Result result, const std::string &reject_reason="", const std::string &debug_message="")
Definition: validation.h:98
this block was cached as being invalid and we didn&#39;t store the reason why
std::string ToString() const
Definition: validation.h:122
the block failed to meet one of our checkpoints
Result GetResult() const
Definition: validation.h:119
std::string m_debug_message
Definition: validation.h:95
invalid by consensus rules (excluding any below reasons)
the block&#39;s data didn&#39;t match the data committed to by the PoW
A block this one builds on is invalid.
bool IsInvalid() const
Definition: validation.h:117
Invalid by a change to consensus rules more recent than SegWit.
block timestamp was > 2 hours in the future (or our clock is bad)
std::string m_reject_reason
Definition: validation.h:94
network rule violation (DoS value may be set)
Definition: validation.h:90
std::string GetRejectReason() const
Definition: validation.h:120
Tx already in mempool or conflicts with a tx in the chain Currently this is only used if the transact...
didn&#39;t meet our local policy rules
bool IsError() const
Definition: validation.h:118
TxValidationResult
A "reason" why a transaction was invalid, suitable for determining whether the provider of the transa...
Definition: validation.h:16