You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

validation.h 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2016 The Starwels developers
  3. // Distributed under the MIT software license, see the accompanying
  4. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. #ifndef STARWELS_VALIDATION_H
  6. #define STARWELS_VALIDATION_H
  7. #if defined(HAVE_CONFIG_H)
  8. #include "config/starwels-config.h"
  9. #endif
  10. #include "amount.h"
  11. #include "coins.h"
  12. #include "fs.h"
  13. #include "protocol.h" // For CMessageHeader::MessageStartChars
  14. #include "policy/feerate.h"
  15. #include "script/script_error.h"
  16. #include "sync.h"
  17. #include "versionbits.h"
  18. #include <algorithm>
  19. #include <exception>
  20. #include <map>
  21. #include <set>
  22. #include <stdint.h>
  23. #include <string>
  24. #include <utility>
  25. #include <vector>
  26. #include <atomic>
  27. class CBlockIndex;
  28. class CBlockTreeDB;
  29. class CChainParams;
  30. class CCoinsViewDB;
  31. class CInv;
  32. class CConnman;
  33. class CScriptCheck;
  34. class CBlockPolicyEstimator;
  35. class CTxMemPool;
  36. class CValidationState;
  37. struct ChainTxData;
  38. struct PrecomputedTransactionData;
  39. struct LockPoints;
  40. /** Default for DEFAULT_WHITELISTRELAY. */
  41. static const bool DEFAULT_WHITELISTRELAY = true;
  42. /** Default for DEFAULT_WHITELISTFORCERELAY. */
  43. static const bool DEFAULT_WHITELISTFORCERELAY = true;
  44. /** Default for -minrelaytxfee, minimum relay fee for transactions */
  45. static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
  46. //! -maxtxfee default
  47. static const CAmount DEFAULT_TRANSACTION_MAXFEE = 0.1 * COIN;
  48. //! Discourage users to set fees higher than this amount (in satoshis) per kB
  49. static const CAmount HIGH_TX_FEE_PER_KB = 0.01 * COIN;
  50. //! -maxtxfee will warn if called with a higher fee than this amount (in satoshis)
  51. static const CAmount HIGH_MAX_TX_FEE = 100 * HIGH_TX_FEE_PER_KB;
  52. /** Default for -limitancestorcount, max number of in-mempool ancestors */
  53. static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25;
  54. /** Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors */
  55. static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
  56. /** Default for -limitdescendantcount, max number of in-mempool descendants */
  57. static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
  58. /** Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants */
  59. static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
  60. /** Default for -mempoolexpiry, expiration time for mempool transactions in hours */
  61. static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
  62. /** Maximum kilobytes for transactions to store for processing during reorg */
  63. static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20000;
  64. /** The maximum size of a blk?????.dat file (since 0.8) */
  65. static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
  66. /** The pre-allocation chunk size for blk?????.dat files (since 0.8) */
  67. static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
  68. /** The pre-allocation chunk size for rev?????.dat files (since 0.8) */
  69. static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
  70. /** Maximum number of script-checking threads allowed */
  71. static const int MAX_SCRIPTCHECK_THREADS = 16;
  72. /** -par default (number of script-checking threads, 0 = auto) */
  73. static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
  74. /** Number of blocks that can be requested at any given time from a single peer. */
  75. static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
  76. /** Timeout in seconds during which a peer must stall block download progress before being disconnected. */
  77. static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
  78. /** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends
  79. * less than this number, we reached its tip. Changing this value is a protocol upgrade. */
  80. static const unsigned int MAX_HEADERS_RESULTS = 2000;
  81. /** Maximum depth of blocks we're willing to serve as compact blocks to peers
  82. * when requested. For older blocks, a regular BLOCK response will be sent. */
  83. static const int MAX_CMPCTBLOCK_DEPTH = 5;
  84. /** Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for. */
  85. static const int MAX_BLOCKTXN_DEPTH = 10;
  86. /** Size of the "block download window": how far ahead of our current height do we fetch?
  87. * Larger windows tolerate larger download speed differences between peer, but increase the potential
  88. * degree of disordering of blocks on disk (which make reindexing and in the future perhaps pruning
  89. * harder). We'll probably want to make this a per-peer adaptive value at some point. */
  90. static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
  91. /** Time to wait (in seconds) between writing blocks/block index to disk. */
  92. static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
  93. /** Time to wait (in seconds) between flushing chainstate to disk. */
  94. static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
  95. /** Maximum length of reject messages. */
  96. static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
  97. /** Average delay between local address broadcasts in seconds. */
  98. static const unsigned int AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL = 24 * 60 * 60;
  99. /** Average delay between peer address broadcasts in seconds. */
  100. static const unsigned int AVG_ADDRESS_BROADCAST_INTERVAL = 30;
  101. /** Average delay between trickled inventory transmissions in seconds.
  102. * Blocks and whitelisted receivers bypass this, outbound peers get half this delay. */
  103. static const unsigned int INVENTORY_BROADCAST_INTERVAL = 5;
  104. /** Maximum number of inventory items to send per transmission.
  105. * Limits the impact of low-fee transaction floods. */
  106. static const unsigned int INVENTORY_BROADCAST_MAX = 7 * INVENTORY_BROADCAST_INTERVAL;
  107. /** Average delay between feefilter broadcasts in seconds. */
  108. static const unsigned int AVG_FEEFILTER_BROADCAST_INTERVAL = 10 * 60;
  109. /** Maximum feefilter broadcast delay after significant change. */
  110. static const unsigned int MAX_FEEFILTER_CHANGE_DELAY = 5 * 60;
  111. /** Block download timeout base, expressed in millionths of the block interval (i.e. 10 min) */
  112. static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000;
  113. /** Additional block download timeout per parallel downloading peer (i.e. 5 min) */
  114. static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000;
  115. static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
  116. /** Maximum age of our tip in seconds for us to be considered current for fee estimation */
  117. static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60;
  118. /** Default for -permitbaremultisig */
  119. static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
  120. static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
  121. static const bool DEFAULT_TXINDEX = false;
  122. static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
  123. /** Default for -persistmempool */
  124. static const bool DEFAULT_PERSIST_MEMPOOL = true;
  125. /** Default for -mempoolreplacement */
  126. static const bool DEFAULT_ENABLE_REPLACEMENT = true;
  127. /** Default for using fee filter */
  128. static const bool DEFAULT_FEEFILTER = true;
  129. /** Maximum number of headers to announce when relaying blocks with headers message.*/
  130. static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;
  131. /** Maximum number of unconnecting headers announcements before DoS score */
  132. static const int MAX_UNCONNECTING_HEADERS = 10;
  133. static const bool DEFAULT_PEERBLOOMFILTERS = true;
  134. /** Default for -stopatheight */
  135. static const int DEFAULT_STOPATHEIGHT = 0;
  136. struct BlockHasher
  137. {
  138. size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); }
  139. };
  140. extern CScript COINBASE_FLAGS;
  141. extern CCriticalSection cs_main;
  142. extern CBlockPolicyEstimator feeEstimator;
  143. extern CTxMemPool mempool;
  144. typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
  145. extern BlockMap mapBlockIndex;
  146. extern uint64_t nLastBlockTx;
  147. extern uint64_t nLastBlockWeight;
  148. extern const std::string strMessageMagic;
  149. extern CWaitableCriticalSection csBestBlock;
  150. extern CConditionVariable cvBlockChange;
  151. extern std::atomic_bool fImporting;
  152. extern bool fReindex;
  153. extern int nScriptCheckThreads;
  154. extern bool fTxIndex;
  155. extern bool fIsBareMultisigStd;
  156. extern bool fRequireStandard;
  157. extern bool fCheckBlockIndex;
  158. extern bool fCheckpointsEnabled;
  159. extern size_t nCoinCacheUsage;
  160. /** A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) */
  161. extern CFeeRate minRelayTxFee;
  162. /** Absolute maximum transaction fee (in satoshis) used by wallet and mempool (rejects high fee in sendrawtransaction) */
  163. extern CAmount maxTxFee;
  164. /** If the tip is older than this (in seconds), the node is considered to be in initial block download. */
  165. extern int64_t nMaxTipAge;
  166. extern bool fEnableReplacement;
  167. /** Block hash whose ancestors we will assume to have valid scripts without checking them. */
  168. extern uint256 hashAssumeValid;
  169. /** Minimum work we will assume exists on some valid chain. */
  170. extern arith_uint256 nMinimumChainWork;
  171. /** Best header we've seen so far (used for getheaders queries' starting points). */
  172. extern CBlockIndex *pindexBestHeader;
  173. /** Minimum disk space required - used in CheckDiskSpace() */
  174. static const uint64_t nMinDiskSpace = 52428800;
  175. /** Pruning-related variables and constants */
  176. /** True if any block files have ever been pruned. */
  177. extern bool fHavePruned;
  178. /** True if we're running in -prune mode. */
  179. extern bool fPruneMode;
  180. /** Number of MiB of block files that we're trying to stay below. */
  181. extern uint64_t nPruneTarget;
  182. /** Block files containing a block-height within MIN_BLOCKS_TO_KEEP of chainActive.Tip() will not be pruned. */
  183. static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
  184. static const signed int DEFAULT_CHECKBLOCKS = 6;
  185. static const unsigned int DEFAULT_CHECKLEVEL = 3;
  186. // Require that user allocate at least 550MB for block & undo files (blk???.dat and rev???.dat)
  187. // At 1MB per block, 288 blocks = 288MB.
  188. // Add 15% for Undo data = 331MB
  189. // Add 20% for Orphan block rate = 397MB
  190. // We want the low water mark after pruning to be at least 397 MB and since we prune in
  191. // full block file chunks, we need the high water mark which triggers the prune to be
  192. // one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB
  193. // Setting the target to > than 550MB will make it likely we can respect the target.
  194. static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
  195. /**
  196. * Process an incoming block. This only returns after the best known valid
  197. * block is made active. Note that it does not, however, guarantee that the
  198. * specific block passed to it has been checked for validity!
  199. *
  200. * If you want to *possibly* get feedback on whether pblock is valid, you must
  201. * install a CValidationInterface (see validationinterface.h) - this will have
  202. * its BlockChecked method called whenever *any* block completes validation.
  203. *
  204. * Note that we guarantee that either the proof-of-work is valid on pblock, or
  205. * (and possibly also) BlockChecked will have been called.
  206. *
  207. * Call without cs_main held.
  208. *
  209. * @param[in] pblock The block we want to process.
  210. * @param[in] fForceProcessing Process this block even if unrequested; used for non-network block sources and whitelisted peers.
  211. * @param[out] fNewBlock A boolean which is set to indicate if the block was first received via this call
  212. * @return True if state.IsValid()
  213. */
  214. bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock);
  215. /**
  216. * Process incoming block headers.
  217. *
  218. * Call without cs_main held.
  219. *
  220. * @param[in] block The block headers themselves
  221. * @param[out] state This may be set to an Error state if any error occurred processing them
  222. * @param[in] chainparams The params for the chain we want to connect to
  223. * @param[out] ppindex If set, the pointer will be set to point to the last new block index object for the given headers
  224. * @param[out] first_invalid First header that fails validation, if one exists
  225. */
  226. bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, CValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex=nullptr, CBlockHeader *first_invalid=nullptr);
  227. /** Check whether enough disk space is available for an incoming block */
  228. bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
  229. /** Open a block file (blk?????.dat) */
  230. FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
  231. /** Translation to a filesystem path */
  232. fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix);
  233. /** Import blocks from an external file */
  234. bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp = nullptr);
  235. /** Ensures we have a genesis block in the block tree, possibly writing one to disk. */
  236. bool LoadGenesisBlock(const CChainParams& chainparams);
  237. /** Load the block tree and coins database from disk,
  238. * initializing state if we're running with -reindex. */
  239. bool LoadBlockIndex(const CChainParams& chainparams);
  240. /** Update the chain tip based on database information. */
  241. bool LoadChainTip(const CChainParams& chainparams);
  242. /** Unload database information */
  243. void UnloadBlockIndex();
  244. /** Run an instance of the script checking thread */
  245. void ThreadScriptCheck();
  246. /** Check whether we are doing an initial block download (synchronizing from disk or network) */
  247. bool IsInitialBlockDownload();
  248. /** Retrieve a transaction (from memory pool, or from disk, if possible) */
  249. bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false);
  250. /** Find the best known block, and make it the tip of the block chain */
  251. bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
  252. CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
  253. /** Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). */
  254. double GuessVerificationProgress(const ChainTxData& data, CBlockIndex* pindex);
  255. /**
  256. * Mark one block file as pruned.
  257. */
  258. void PruneOneBlockFile(const int fileNumber);
  259. /**
  260. * Actually unlink the specified files
  261. */
  262. void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune);
  263. /** Create a new block index entry for a given block hash */
  264. CBlockIndex * InsertBlockIndex(uint256 hash);
  265. /** Flush all state, indexes and buffers to disk. */
  266. void FlushStateToDisk();
  267. /** Prune block files and flush state to disk. */
  268. void PruneAndFlush();
  269. /** Prune block files up to a given height */
  270. void PruneBlockFilesManual(int nManualPruneHeight);
  271. /** (try to) add transaction to memory pool
  272. * plTxnReplaced will be appended to with all transactions replaced from mempool **/
  273. bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
  274. bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced = nullptr,
  275. bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0);
  276. /** Convert CValidationState to a human-readable message for logging */
  277. std::string FormatStateMessage(const CValidationState &state);
  278. /** Get the BIP9 state for a given deployment at the current tip. */
  279. ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos);
  280. /** Get the numerical statistics for the BIP9 state for a given deployment at the current tip. */
  281. BIP9Stats VersionBitsTipStatistics(const Consensus::Params& params, Consensus::DeploymentPos pos);
  282. /** Get the block height at which the BIP9 deployment switched into the state for the block building on the current tip. */
  283. int VersionBitsTipStateSinceHeight(const Consensus::Params& params, Consensus::DeploymentPos pos);
  284. /** Apply the effects of this transaction on the UTXO set represented by view */
  285. void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
  286. /** Transaction validation functions */
  287. /**
  288. * Check if transaction will be final in the next block to be created.
  289. *
  290. * Calls IsFinalTx() with current block height and appropriate block time.
  291. *
  292. * See consensus/consensus.h for flag definitions.
  293. */
  294. bool CheckFinalTx(const CTransaction &tx, int flags = -1);
  295. /**
  296. * Test whether the LockPoints height and time are still valid on the current chain
  297. */
  298. bool TestLockPointValidity(const LockPoints* lp);
  299. /**
  300. * Check if transaction will be BIP 68 final in the next block to be created.
  301. *
  302. * Simulates calling SequenceLocks() with data from the tip of the current active chain.
  303. * Optionally stores in LockPoints the resulting height and time calculated and the hash
  304. * of the block needed for calculation or skips the calculation and uses the LockPoints
  305. * passed in for evaluation.
  306. * The LockPoints should not be considered valid if CheckSequenceLocks returns false.
  307. *
  308. * See consensus/consensus.h for flag definitions.
  309. */
  310. bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false);
  311. /**
  312. * Closure representing one script verification
  313. * Note that this stores references to the spending transaction
  314. */
  315. class CScriptCheck
  316. {
  317. private:
  318. CScript scriptPubKey;
  319. CAmount amount;
  320. const CTransaction *ptxTo;
  321. unsigned int nIn;
  322. unsigned int nFlags;
  323. bool cacheStore;
  324. ScriptError error;
  325. PrecomputedTransactionData *txdata;
  326. public:
  327. CScriptCheck(): amount(0), ptxTo(0), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
  328. CScriptCheck(const CScript& scriptPubKeyIn, const CAmount amountIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
  329. scriptPubKey(scriptPubKeyIn), amount(amountIn),
  330. ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
  331. bool operator()();
  332. void swap(CScriptCheck &check) {
  333. scriptPubKey.swap(check.scriptPubKey);
  334. std::swap(ptxTo, check.ptxTo);
  335. std::swap(amount, check.amount);
  336. std::swap(nIn, check.nIn);
  337. std::swap(nFlags, check.nFlags);
  338. std::swap(cacheStore, check.cacheStore);
  339. std::swap(error, check.error);
  340. std::swap(txdata, check.txdata);
  341. }
  342. ScriptError GetScriptError() const { return error; }
  343. };
  344. /** Initializes the script-execution cache */
  345. void InitScriptExecutionCache();
  346. /** Functions for disk access for blocks */
  347. bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams);
  348. bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams);
  349. /** Functions for validating blocks and updating the block tree */
  350. /** Context-independent validity checks */
  351. bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
  352. /** Check a block is completely valid from start to finish (only works on top of our current best block, with cs_main held) */
  353. bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
  354. /** Check whether witness commitments are required for block. */
  355. bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
  356. /** When there are blocks in the active chain with missing data, rewind the chainstate and remove them from the block index */
  357. bool RewindBlockIndex(const CChainParams& params);
  358. /** Update uncommitted block structures (currently: only the witness nonce). This is safe for submitted blocks. */
  359. void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
  360. /** Produce the necessary coinbase commitment for a block (modifies the hash, don't call for mined blocks). */
  361. std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
  362. /** RAII wrapper for VerifyDB: Verify consistency of the block and coin databases */
  363. class CVerifyDB {
  364. public:
  365. CVerifyDB();
  366. ~CVerifyDB();
  367. bool VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth);
  368. };
  369. /** Replay blocks that aren't fully applied to the database. */
  370. bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
  371. /** Find the last common block between the parameter chain and a locator. */
  372. CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator);
  373. /** Mark a block as precious and reorganize. */
  374. bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex *pindex);
  375. /** Mark a block as invalid. */
  376. bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex);
  377. /** Remove invalidity status from a block and its descendants. */
  378. bool ResetBlockFailureFlags(CBlockIndex *pindex);
  379. /** The currently-connected chain of blocks (protected by cs_main). */
  380. extern CChain chainActive;
  381. /** Global variable that points to the coins database (protected by cs_main) */
  382. extern CCoinsViewDB *pcoinsdbview;
  383. /** Global variable that points to the active CCoinsView (protected by cs_main) */
  384. extern CCoinsViewCache *pcoinsTip;
  385. /** Global variable that points to the active block tree (protected by cs_main) */
  386. extern CBlockTreeDB *pblocktree;
  387. /**
  388. * Return the spend height, which is one more than the inputs.GetBestBlock().
  389. * While checking, GetBestBlock() refers to the parent block. (protected by cs_main)
  390. * This is also true for mempool checks.
  391. */
  392. int GetSpendHeight(const CCoinsViewCache& inputs);
  393. extern VersionBitsCache versionbitscache;
  394. /**
  395. * Determine what nVersion a new block should use.
  396. */
  397. int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params);
  398. /** Reject codes greater or equal to this can be returned by AcceptToMemPool
  399. * for transactions, to signal internal conditions. They cannot and should not
  400. * be sent over the P2P network.
  401. */
  402. static const unsigned int REJECT_INTERNAL = 0x100;
  403. /** Too high fee. Can not be triggered by P2P transactions */
  404. static const unsigned int REJECT_HIGHFEE = 0x100;
  405. /** Get block file info entry for one block file */
  406. CBlockFileInfo* GetBlockFileInfo(size_t n);
  407. /** Dump the mempool to disk. */
  408. void DumpMempool();
  409. /** Load the mempool from disk. */
  410. bool LoadMempool();
  411. #endif // STARWELS_VALIDATION_H