Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

specialtx.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 The Dash Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <chainparams.h>
6 #include <clientversion.h>
7 #include <consensus/validation.h>
8 #include <hash.h>
9 #include <primitives/block.h>
10 #include <primitives/transaction.h>
11 #include <validation.h>
12 
13 #include <evo/cbtx.h>
14 #include <evo/deterministicmns.h>
15 #include <evo/specialtx.h>
16 
19 
20 bool CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state)
21 {
22  if (tx.nVersion != 3 || tx.nType == TRANSACTION_NORMAL)
23  return true;
24 
25  if (pindexPrev && pindexPrev->nHeight + 1 < Params().GetConsensus().DIP0003Height) {
26  return state.DoS(10, false, REJECT_INVALID, "bad-tx-type");
27  }
28 
29  try {
30  switch (tx.nType) {
32  return CheckProRegTx(tx, pindexPrev, state);
34  return CheckProUpServTx(tx, pindexPrev, state);
36  return CheckProUpRegTx(tx, pindexPrev, state);
38  return CheckProUpRevTx(tx, pindexPrev, state);
40  return CheckCbTx(tx, pindexPrev, state);
42  return llmq::CheckLLMQCommitment(tx, pindexPrev, state);
43  }
44  } catch (const std::exception& e) {
45  LogPrintf("%s -- failed: %s\n", __func__, e.what());
46  return state.DoS(100, false, REJECT_INVALID, "failed-check-special-tx");
47  }
48 
49  return state.DoS(10, false, REJECT_INVALID, "bad-tx-type-check");
50 }
51 
52 bool ProcessSpecialTx(const CTransaction& tx, const CBlockIndex* pindex, CValidationState& state)
53 {
54  if (tx.nVersion != 3 || tx.nType == TRANSACTION_NORMAL) {
55  return true;
56  }
57 
58  switch (tx.nType) {
63  return true; // handled in batches per block
65  return true; // nothing to do
67  return true; // handled per block
68  }
69 
70  return state.DoS(100, false, REJECT_INVALID, "bad-tx-type-proc");
71 }
72 
73 bool UndoSpecialTx(const CTransaction& tx, const CBlockIndex* pindex)
74 {
75  if (tx.nVersion != 3 || tx.nType == TRANSACTION_NORMAL) {
76  return true;
77  }
78 
79  switch (tx.nType) {
84  return true; // handled in batches per block
86  return true; // nothing to do
88  return true; // handled per block
89  }
90 
91  return false;
92 }
93 
94 bool ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state, bool fJustCheck, bool fCheckCbTxMerleRoots)
95 {
96  static int64_t nTimeLoop = 0;
97  static int64_t nTimeQuorum = 0;
98  static int64_t nTimeDMN = 0;
99  static int64_t nTimeMerkle = 0;
100 
101  try {
102  int64_t nTime1 = GetTimeMicros();
103 
104  for (int i = 0; i < (int)block.vtx.size(); i++) {
105  const CTransaction& tx = *block.vtx[i];
106  if (!CheckSpecialTx(tx, pindex->pprev, state)) {
107  // pass the state returned by the function above
108  return false;
109  }
110  if (!ProcessSpecialTx(tx, pindex, state)) {
111  // pass the state returned by the function above
112  return false;
113  }
114  }
115 
116  int64_t nTime2 = GetTimeMicros(); nTimeLoop += nTime2 - nTime1;
117  LogPrint(BCLog::BENCHMARK, " - Loop: %.2fms [%.2fs]\n", 0.001 * (nTime2 - nTime1), nTimeLoop * 0.000001);
118 
119  if (!llmq::quorumBlockProcessor->ProcessBlock(block, pindex, state)) {
120  // pass the state returned by the function above
121  return false;
122  }
123 
124  int64_t nTime3 = GetTimeMicros(); nTimeQuorum += nTime3 - nTime2;
125  LogPrint(BCLog::BENCHMARK, " - quorumBlockProcessor: %.2fms [%.2fs]\n", 0.001 * (nTime3 - nTime2), nTimeQuorum * 0.000001);
126 
127  if (!deterministicMNManager->ProcessBlock(block, pindex, state, fJustCheck)) {
128  // pass the state returned by the function above
129  return false;
130  }
131 
132  int64_t nTime4 = GetTimeMicros(); nTimeDMN += nTime4 - nTime3;
133  LogPrint(BCLog::BENCHMARK, " - deterministicMNManager: %.2fms [%.2fs]\n", 0.001 * (nTime4 - nTime3), nTimeDMN * 0.000001);
134 
135  if (fCheckCbTxMerleRoots && !CheckCbTxMerkleRoots(block, pindex, state)) {
136  // pass the state returned by the function above
137  return false;
138  }
139 
140  int64_t nTime5 = GetTimeMicros(); nTimeMerkle += nTime5 - nTime4;
141  LogPrint(BCLog::BENCHMARK, " - CheckCbTxMerkleRoots: %.2fms [%.2fs]\n", 0.001 * (nTime5 - nTime4), nTimeMerkle * 0.000001);
142  } catch (const std::exception& e) {
143  LogPrintf("%s -- failed: %s\n", __func__, e.what());
144  return state.DoS(100, false, REJECT_INVALID, "failed-procspectxsinblock");
145  }
146 
147  return true;
148 }
149 
150 bool UndoSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex)
151 {
152  try {
153  for (int i = (int)block.vtx.size() - 1; i >= 0; --i) {
154  const CTransaction& tx = *block.vtx[i];
155  if (!UndoSpecialTx(tx, pindex)) {
156  return false;
157  }
158  }
159 
160  if (!deterministicMNManager->UndoBlock(block, pindex)) {
161  return false;
162  }
163 
164  if (!llmq::quorumBlockProcessor->UndoBlock(block, pindex)) {
165  return false;
166  }
167  } catch (const std::exception& e) {
168  return error(strprintf("%s -- failed: %s\n", __func__, e.what()).c_str());
169  }
170 
171  return true;
172 }
173 
175 {
177  for (const auto& in : tx.vin) {
178  hw << in.prevout;
179  }
180  return hw.GetHash();
181 }
bool CheckProUpServTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CValidationState &state)
Definition: providertx.cpp:218
bool CheckCbTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CValidationState &state)
Definition: cbtx.cpp:18
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:177
bool CheckCbTxMerkleRoots(const CBlock &block, const CBlockIndex *pindex, CValidationState &state)
Definition: cbtx.cpp:52
Definition: block.h:72
#define strprintf
Definition: tinyformat.h:1066
CQuorumBlockProcessor * quorumBlockProcessor
uint256 CalcTxInputsHash(const CTransaction &tx)
Definition: specialtx.cpp:174
int64_t GetTimeMicros()
Returns the system time (not mockable)
Definition: utiltime.cpp:63
bool DoS(int level, bool ret=false, unsigned int chRejectCodeIn=0, const std::string &strRejectReasonIn="", bool corruptionIn=false, const std::string &strDebugMessageIn="")
Definition: validation.h:36
bool CheckLLMQCommitment(const CTransaction &tx, const CBlockIndex *pindexPrev, CValidationState &state)
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
static const unsigned char REJECT_INVALID
Definition: validation.h:13
const std::vector< CTxIn > vin
Definition: transaction.h:215
bool UndoSpecialTxsInBlock(const CBlock &block, const CBlockIndex *pindex)
Definition: specialtx.cpp:150
bool UndoSpecialTx(const CTransaction &tx, const CBlockIndex *pindex)
Definition: specialtx.cpp:73
bool ProcessSpecialTxsInBlock(const CBlock &block, const CBlockIndex *pindex, CValidationState &state, bool fJustCheck, bool fCheckCbTxMerleRoots)
Definition: specialtx.cpp:94
#define LogPrintf(...)
Definition: util.h:203
bool CheckProRegTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CValidationState &state)
Definition: providertx.cpp:86
bool CheckProUpRevTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CValidationState &state)
Definition: providertx.cpp:358
const int16_t nVersion
Definition: transaction.h:217
#define LogPrint(category,...)
Definition: util.h:214
uint256 GetHash()
Definition: hash.h:203
Capture information about block/transaction validation.
Definition: validation.h:22
256-bit opaque blob.
Definition: uint256.h:123
std::vector< CTransactionRef > vtx
Definition: block.h:76
bool ProcessSpecialTx(const CTransaction &tx, const CBlockIndex *pindex, CValidationState &state)
Definition: specialtx.cpp:52
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
const CChainParams & Params()
Return the currently selected parameters.
bool CheckProUpRegTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CValidationState &state)
Definition: providertx.cpp:274
bool error(const char *fmt, const Args &... args)
Definition: util.h:222
A writer stream (for serialization) that computes a 256-bit hash.
Definition: hash.h:184
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:183
static const int CLIENT_VERSION
dashd-res.rc includes this file, but it cannot cope with real c++ code.
Definition: clientversion.h:38
const int16_t nType
Definition: transaction.h:218
bool CheckSpecialTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CValidationState &state)
Definition: specialtx.cpp:20
Released under the MIT license