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.

main.h 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2014 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. #ifndef BITCOIN_MAIN_H
  6. #define BITCOIN_MAIN_H
  7. #if defined(HAVE_CONFIG_H)
  8. #include "config/bitcoin-config.h"
  9. #endif
  10. #include "amount.h"
  11. #include "chain.h"
  12. #include "chainparams.h"
  13. #include "coins.h"
  14. #include "primitives/block.h"
  15. #include "primitives/transaction.h"
  16. #include "net.h"
  17. #include "script/script.h"
  18. #include "script/sigcache.h"
  19. #include "script/standard.h"
  20. #include "sync.h"
  21. #include "tinyformat.h"
  22. #include "txmempool.h"
  23. #include "uint256.h"
  24. #include <algorithm>
  25. #include <exception>
  26. #include <map>
  27. #include <set>
  28. #include <stdint.h>
  29. #include <string>
  30. #include <utility>
  31. #include <vector>
  32. #include <boost/unordered_map.hpp>
  33. class CBlockIndex;
  34. class CBlockTreeDB;
  35. class CBloomFilter;
  36. class CInv;
  37. class CScriptCheck;
  38. class CValidationInterface;
  39. class CValidationState;
  40. struct CNodeStateStats;
  41. /** Default for -blockmaxsize and -blockminsize, which control the range of sizes the mining code will create **/
  42. static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 750000;
  43. static const unsigned int DEFAULT_BLOCK_MIN_SIZE = 0;
  44. /** Default for -blockprioritysize, maximum space for zero/low-fee transactions **/
  45. static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 50000;
  46. /** The maximum size for transactions we're willing to relay/mine */
  47. static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
  48. /** The maximum allowed number of signature check operations in a block (network rule) */
  49. static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
  50. /** Maximum number of signature check operations in an IsStandard() P2SH script */
  51. static const unsigned int MAX_P2SH_SIGOPS = 15;
  52. /** The maximum number of sigops we're willing to relay/mine in a single tx */
  53. static const unsigned int MAX_STANDARD_TX_SIGOPS = MAX_BLOCK_SIGOPS/5;
  54. /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
  55. static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
  56. /** The maximum size of a blk?????.dat file (since 0.8) */
  57. static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
  58. /** The pre-allocation chunk size for blk?????.dat files (since 0.8) */
  59. static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
  60. /** The pre-allocation chunk size for rev?????.dat files (since 0.8) */
  61. static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
  62. /** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
  63. static const int COINBASE_MATURITY = 100;
  64. /** Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp. */
  65. static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
  66. /** Maximum number of script-checking threads allowed */
  67. static const int MAX_SCRIPTCHECK_THREADS = 16;
  68. /** -par default (number of script-checking threads, 0 = auto) */
  69. static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
  70. /** Number of blocks that can be requested at any given time from a single peer. */
  71. static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
  72. /** Timeout in seconds during which a peer must stall block download progress before being disconnected. */
  73. static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
  74. /** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends
  75. * less than this number, we reached their tip. Changing this value is a protocol upgrade. */
  76. static const unsigned int MAX_HEADERS_RESULTS = 2000;
  77. /** Size of the "block download window": how far ahead of our current height do we fetch?
  78. * Larger windows tolerate larger download speed differences between peer, but increase the potential
  79. * degree of disordering of blocks on disk (which make reindexing and in the future perhaps pruning
  80. * harder). We'll probably want to make this a per-peer adaptive value at some point. */
  81. static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
  82. /** Time to wait (in seconds) between writing blockchain state to disk. */
  83. static const unsigned int DATABASE_WRITE_INTERVAL = 3600;
  84. /** Maximum length of reject messages. */
  85. static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
  86. /** "reject" message codes */
  87. static const unsigned char REJECT_MALFORMED = 0x01;
  88. static const unsigned char REJECT_INVALID = 0x10;
  89. static const unsigned char REJECT_OBSOLETE = 0x11;
  90. static const unsigned char REJECT_DUPLICATE = 0x12;
  91. static const unsigned char REJECT_NONSTANDARD = 0x40;
  92. static const unsigned char REJECT_DUST = 0x41;
  93. static const unsigned char REJECT_INSUFFICIENTFEE = 0x42;
  94. static const unsigned char REJECT_CHECKPOINT = 0x43;
  95. struct BlockHasher
  96. {
  97. size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); }
  98. };
  99. extern CScript COINBASE_FLAGS;
  100. extern CCriticalSection cs_main;
  101. extern CTxMemPool mempool;
  102. typedef boost::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
  103. extern BlockMap mapBlockIndex;
  104. extern uint64_t nLastBlockTx;
  105. extern uint64_t nLastBlockSize;
  106. extern const std::string strMessageMagic;
  107. extern int64_t nTimeBestReceived;
  108. extern CWaitableCriticalSection csBestBlock;
  109. extern CConditionVariable cvBlockChange;
  110. extern bool fImporting;
  111. extern bool fReindex;
  112. extern int nScriptCheckThreads;
  113. extern bool fTxIndex;
  114. extern bool fIsBareMultisigStd;
  115. extern bool fCheckBlockIndex;
  116. extern unsigned int nCoinCacheSize;
  117. extern CFeeRate minRelayTxFee;
  118. /** Best header we've seen so far (used for getheaders queries' starting points). */
  119. extern CBlockIndex *pindexBestHeader;
  120. /** Minimum disk space required - used in CheckDiskSpace() */
  121. static const uint64_t nMinDiskSpace = 52428800;
  122. /** Register with a network node to receive its signals */
  123. void RegisterNodeSignals(CNodeSignals& nodeSignals);
  124. /** Unregister a network node */
  125. void UnregisterNodeSignals(CNodeSignals& nodeSignals);
  126. /**
  127. * Process an incoming block. This only returns after the best known valid
  128. * block is made active. Note that it does not, however, guarantee that the
  129. * specific block passed to it has been checked for validity!
  130. *
  131. * @param[out] state This may be set to an Error state if any error occurred processing it, including during validation/connection/etc of otherwise unrelated blocks during reorganisation; or it may be set to an Invalid state if pblock is itself invalid (but this is not guaranteed even when the block is checked). If you want to *possibly* get feedback on whether pblock is valid, you must also install a CValidationInterface (see validationinterface.h) - this will have its BlockChecked method called whenever *any* block completes validation.
  132. * @param[in] pfrom The node which we are receiving the block from; it is added to mapBlockSource and may be penalised if the block is invalid.
  133. * @param[in] pblock The block we want to process.
  134. * @param[out] dbp If pblock is stored to disk (or already there), this will be set to its location.
  135. * @return True if state.IsValid()
  136. */
  137. bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp = NULL);
  138. /** Check whether enough disk space is available for an incoming block */
  139. bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
  140. /** Open a block file (blk?????.dat) */
  141. FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
  142. /** Open an undo file (rev?????.dat) */
  143. FILE* OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly = false);
  144. /** Translation to a filesystem path */
  145. boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix);
  146. /** Import blocks from an external file */
  147. bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp = NULL);
  148. /** Initialize a new block tree database + block data on disk */
  149. bool InitBlockIndex();
  150. /** Load the block tree and coins database from disk */
  151. bool LoadBlockIndex();
  152. /** Unload database information */
  153. void UnloadBlockIndex();
  154. /** Process protocol messages received from a given node */
  155. bool ProcessMessages(CNode* pfrom);
  156. /**
  157. * Send queued protocol messages to be sent to a give node.
  158. *
  159. * @param[in] pto The node which we are sending messages to.
  160. * @param[in] fSendTrickle When true send the trickled data, otherwise trickle the data until true.
  161. */
  162. bool SendMessages(CNode* pto, bool fSendTrickle);
  163. /** Run an instance of the script checking thread */
  164. void ThreadScriptCheck();
  165. /** Check whether we are doing an initial block download (synchronizing from disk or network) */
  166. bool IsInitialBlockDownload();
  167. /** Format a string that describes several potential problems detected by the core */
  168. std::string GetWarnings(std::string strFor);
  169. /** Retrieve a transaction (from memory pool, or from disk, if possible) */
  170. bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, bool fAllowSlow = false);
  171. /** Find the best known block, and make it the tip of the block chain */
  172. bool ActivateBestChain(CValidationState &state, CBlock *pblock = NULL);
  173. CAmount GetBlockValue(int nHeight, const CAmount& nFees);
  174. /** Create a new block index entry for a given block hash */
  175. CBlockIndex * InsertBlockIndex(uint256 hash);
  176. /** Abort with a message */
  177. bool AbortNode(const std::string &msg, const std::string &userMessage="");
  178. /** Get statistics from node state */
  179. bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
  180. /** Increase a node's misbehavior score. */
  181. void Misbehaving(NodeId nodeid, int howmuch);
  182. /** Flush all state, indexes and buffers to disk. */
  183. void FlushStateToDisk();
  184. /** (try to) add transaction to memory pool **/
  185. bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,
  186. bool* pfMissingInputs, bool fRejectAbsurdFee=false);
  187. struct CNodeStateStats {
  188. int nMisbehavior;
  189. int nSyncHeight;
  190. int nCommonHeight;
  191. std::vector<int> vHeightInFlight;
  192. };
  193. struct CDiskTxPos : public CDiskBlockPos
  194. {
  195. unsigned int nTxOffset; // after header
  196. ADD_SERIALIZE_METHODS;
  197. template <typename Stream, typename Operation>
  198. inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
  199. READWRITE(*(CDiskBlockPos*)this);
  200. READWRITE(VARINT(nTxOffset));
  201. }
  202. CDiskTxPos(const CDiskBlockPos &blockIn, unsigned int nTxOffsetIn) : CDiskBlockPos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) {
  203. }
  204. CDiskTxPos() {
  205. SetNull();
  206. }
  207. void SetNull() {
  208. CDiskBlockPos::SetNull();
  209. nTxOffset = 0;
  210. }
  211. };
  212. CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree);
  213. /**
  214. * Check transaction inputs, and make sure any
  215. * pay-to-script-hash transactions are evaluating IsStandard scripts
  216. *
  217. * Why bother? To avoid denial-of-service attacks; an attacker
  218. * can submit a standard HASH... OP_EQUAL transaction,
  219. * which will get accepted into blocks. The redemption
  220. * script can be anything; an attacker could use a very
  221. * expensive-to-check-upon-redemption script like:
  222. * DUP CHECKSIG DROP ... repeated 100 times... OP_1
  223. */
  224. /**
  225. * Check for standard transaction types
  226. * @param[in] mapInputs Map of previous transactions that have outputs we're spending
  227. * @return True if all inputs (scriptSigs) use only standard transaction forms
  228. */
  229. bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
  230. /**
  231. * Count ECDSA signature operations the old-fashioned (pre-0.6) way
  232. * @return number of sigops this transaction's outputs will produce when spent
  233. * @see CTransaction::FetchInputs
  234. */
  235. unsigned int GetLegacySigOpCount(const CTransaction& tx);
  236. /**
  237. * Count ECDSA signature operations in pay-to-script-hash inputs.
  238. *
  239. * @param[in] mapInputs Map of previous transactions that have outputs we're spending
  240. * @return maximum number of sigops required to validate this transaction's inputs
  241. * @see CTransaction::FetchInputs
  242. */
  243. unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& mapInputs);
  244. /**
  245. * Check whether all inputs of this transaction are valid (no double spends, scripts & sigs, amounts)
  246. * This does not modify the UTXO set. If pvChecks is not NULL, script checks are pushed onto it
  247. * instead of being performed inline.
  248. */
  249. bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &view, bool fScriptChecks,
  250. unsigned int flags, bool cacheStore, std::vector<CScriptCheck> *pvChecks = NULL);
  251. /** Apply the effects of this transaction on the UTXO set represented by view */
  252. void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCache &inputs, int nHeight);
  253. /** Context-independent validity checks */
  254. bool CheckTransaction(const CTransaction& tx, CValidationState& state);
  255. /** Check for standard transaction types
  256. * @return True if all outputs (scriptPubKeys) use only standard transaction forms
  257. */
  258. bool IsStandardTx(const CTransaction& tx, std::string& reason);
  259. bool IsFinalTx(const CTransaction &tx, int nBlockHeight = 0, int64_t nBlockTime = 0);
  260. /**
  261. * Closure representing one script verification
  262. * Note that this stores references to the spending transaction
  263. */
  264. class CScriptCheck
  265. {
  266. private:
  267. CScript scriptPubKey;
  268. const CTransaction *ptxTo;
  269. unsigned int nIn;
  270. unsigned int nFlags;
  271. bool cacheStore;
  272. ScriptError error;
  273. public:
  274. CScriptCheck(): ptxTo(0), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
  275. CScriptCheck(const CCoins& txFromIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn) :
  276. scriptPubKey(txFromIn.vout[txToIn.vin[nInIn].prevout.n].scriptPubKey),
  277. ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR) { }
  278. bool operator()();
  279. void swap(CScriptCheck &check) {
  280. scriptPubKey.swap(check.scriptPubKey);
  281. std::swap(ptxTo, check.ptxTo);
  282. std::swap(nIn, check.nIn);
  283. std::swap(nFlags, check.nFlags);
  284. std::swap(cacheStore, check.cacheStore);
  285. std::swap(error, check.error);
  286. }
  287. ScriptError GetScriptError() const { return error; }
  288. };
  289. /** Functions for disk access for blocks */
  290. bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos);
  291. bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos);
  292. bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex);
  293. /** Functions for validating blocks and updating the block tree */
  294. /** Undo the effects of this block (with given index) on the UTXO set represented by coins.
  295. * In case pfClean is provided, operation will try to be tolerant about errors, and *pfClean
  296. * will be true if no problems were found. Otherwise, the return value will be false in case
  297. * of problems. Note that in any case, coins may be modified. */
  298. bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool* pfClean = NULL);
  299. /** Apply the effects of this block (with given index) on the UTXO set represented by coins */
  300. bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false);
  301. /** Context-independent validity checks */
  302. bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true);
  303. bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
  304. /** Context-dependent validity checks */
  305. bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex *pindexPrev);
  306. bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIndex *pindexPrev);
  307. /** Check a block is completely valid from start to finish (only works on top of our current best block, with cs_main held) */
  308. bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex *pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
  309. /** Store block on disk. If dbp is provided, the file is known to already reside on disk */
  310. bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex **pindex, CDiskBlockPos* dbp = NULL);
  311. bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex **ppindex= NULL);
  312. class CBlockFileInfo
  313. {
  314. public:
  315. unsigned int nBlocks; //! number of blocks stored in file
  316. unsigned int nSize; //! number of used bytes of block file
  317. unsigned int nUndoSize; //! number of used bytes in the undo file
  318. unsigned int nHeightFirst; //! lowest height of block in file
  319. unsigned int nHeightLast; //! highest height of block in file
  320. uint64_t nTimeFirst; //! earliest time of block in file
  321. uint64_t nTimeLast; //! latest time of block in file
  322. ADD_SERIALIZE_METHODS;
  323. template <typename Stream, typename Operation>
  324. inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
  325. READWRITE(VARINT(nBlocks));
  326. READWRITE(VARINT(nSize));
  327. READWRITE(VARINT(nUndoSize));
  328. READWRITE(VARINT(nHeightFirst));
  329. READWRITE(VARINT(nHeightLast));
  330. READWRITE(VARINT(nTimeFirst));
  331. READWRITE(VARINT(nTimeLast));
  332. }
  333. void SetNull() {
  334. nBlocks = 0;
  335. nSize = 0;
  336. nUndoSize = 0;
  337. nHeightFirst = 0;
  338. nHeightLast = 0;
  339. nTimeFirst = 0;
  340. nTimeLast = 0;
  341. }
  342. CBlockFileInfo() {
  343. SetNull();
  344. }
  345. std::string ToString() const;
  346. /** update statistics (does not update nSize) */
  347. void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn) {
  348. if (nBlocks==0 || nHeightFirst > nHeightIn)
  349. nHeightFirst = nHeightIn;
  350. if (nBlocks==0 || nTimeFirst > nTimeIn)
  351. nTimeFirst = nTimeIn;
  352. nBlocks++;
  353. if (nHeightIn > nHeightLast)
  354. nHeightLast = nHeightIn;
  355. if (nTimeIn > nTimeLast)
  356. nTimeLast = nTimeIn;
  357. }
  358. };
  359. /** Capture information about block/transaction validation */
  360. class CValidationState {
  361. private:
  362. enum mode_state {
  363. MODE_VALID, //! everything ok
  364. MODE_INVALID, //! network rule violation (DoS value may be set)
  365. MODE_ERROR, //! run-time error
  366. } mode;
  367. int nDoS;
  368. std::string strRejectReason;
  369. unsigned char chRejectCode;
  370. bool corruptionPossible;
  371. public:
  372. CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false) {}
  373. bool DoS(int level, bool ret = false,
  374. unsigned char chRejectCodeIn=0, std::string strRejectReasonIn="",
  375. bool corruptionIn=false) {
  376. chRejectCode = chRejectCodeIn;
  377. strRejectReason = strRejectReasonIn;
  378. corruptionPossible = corruptionIn;
  379. if (mode == MODE_ERROR)
  380. return ret;
  381. nDoS += level;
  382. mode = MODE_INVALID;
  383. return ret;
  384. }
  385. bool Invalid(bool ret = false,
  386. unsigned char _chRejectCode=0, std::string _strRejectReason="") {
  387. return DoS(0, ret, _chRejectCode, _strRejectReason);
  388. }
  389. bool Error(std::string strRejectReasonIn="") {
  390. if (mode == MODE_VALID)
  391. strRejectReason = strRejectReasonIn;
  392. mode = MODE_ERROR;
  393. return false;
  394. }
  395. bool Abort(const std::string &msg) {
  396. AbortNode(msg);
  397. return Error(msg);
  398. }
  399. bool IsValid() const {
  400. return mode == MODE_VALID;
  401. }
  402. bool IsInvalid() const {
  403. return mode == MODE_INVALID;
  404. }
  405. bool IsError() const {
  406. return mode == MODE_ERROR;
  407. }
  408. bool IsInvalid(int &nDoSOut) const {
  409. if (IsInvalid()) {
  410. nDoSOut = nDoS;
  411. return true;
  412. }
  413. return false;
  414. }
  415. bool CorruptionPossible() const {
  416. return corruptionPossible;
  417. }
  418. unsigned char GetRejectCode() const { return chRejectCode; }
  419. std::string GetRejectReason() const { return strRejectReason; }
  420. };
  421. /** RAII wrapper for VerifyDB: Verify consistency of the block and coin databases */
  422. class CVerifyDB {
  423. public:
  424. CVerifyDB();
  425. ~CVerifyDB();
  426. bool VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth);
  427. };
  428. /** Find the last common block between the parameter chain and a locator. */
  429. CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator);
  430. /** Mark a block as invalid. */
  431. bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex);
  432. /** Remove invalidity status from a block and its descendants. */
  433. bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex);
  434. /** The currently-connected chain of blocks. */
  435. extern CChain chainActive;
  436. /** Global variable that points to the active CCoinsView (protected by cs_main) */
  437. extern CCoinsViewCache *pcoinsTip;
  438. /** Global variable that points to the active block tree (protected by cs_main) */
  439. extern CBlockTreeDB *pblocktree;
  440. #endif // BITCOIN_MAIN_H