Dash Core  0.12.2.1
P2P Digital Currency
validation.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Copyright (c) 2014-2017 The Dash Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef BITCOIN_VALIDATION_H
8 #define BITCOIN_VALIDATION_H
9 
10 #if defined(HAVE_CONFIG_H)
11 #include "config/dash-config.h"
12 #endif
13 
14 #include "amount.h"
15 #include "chain.h"
16 #include "coins.h"
17 #include "protocol.h" // For CMessageHeader::MessageStartChars
18 #include "script/script_error.h"
19 #include "sync.h"
20 #include "versionbits.h"
21 #include "spentindex.h"
22 
23 #include <algorithm>
24 #include <exception>
25 #include <map>
26 #include <set>
27 #include <stdint.h>
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 #include <atomic>
33 
34 #include <boost/unordered_map.hpp>
35 #include <boost/filesystem/path.hpp>
36 
37 class CBlockIndex;
38 class CBlockTreeDB;
39 class CBloomFilter;
40 class CChainParams;
41 class CInv;
42 class CConnman;
43 class CScriptCheck;
44 class CTxMemPool;
46 class CValidationState;
47 
48 struct LockPoints;
49 
51 static const bool DEFAULT_ALERTS = true;
53 static const bool DEFAULT_WHITELISTRELAY = true;
55 static const bool DEFAULT_WHITELISTFORCERELAY = true;
61 static const unsigned int DEFAULT_LEGACY_MIN_RELAY_TX_FEE = 10000; // was 1000
62 static const unsigned int DEFAULT_DIP0001_MIN_RELAY_TX_FEE = 1000;
64 static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
66 static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25;
68 static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
70 static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
72 static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
74 static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 72;
76 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
78 static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
80 static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
81 
83 static const int MAX_SCRIPTCHECK_THREADS = 16;
85 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
87 static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
89 static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
92 static const unsigned int MAX_HEADERS_RESULTS = 2000;
97 static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
99 static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
101 static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
103 static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
105 static const unsigned int AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL = 24 * 24 * 60;
107 static const unsigned int AVG_ADDRESS_BROADCAST_INTERVAL = 30;
110 static const unsigned int AVG_INVENTORY_BROADCAST_INTERVAL = 5;
112 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 250000;
114 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 125000;
115 
116 static const unsigned int DEFAULT_LIMITFREERELAY = 15;
117 static const bool DEFAULT_RELAYPRIORITY = true;
118 
120 static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
121 static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20;
122 static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
123 static const bool DEFAULT_TXINDEX = true;
124 static const bool DEFAULT_ADDRESSINDEX = false;
125 static const bool DEFAULT_TIMESTAMPINDEX = false;
126 static const bool DEFAULT_SPENTINDEX = false;
127 static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
128 
129 static const bool DEFAULT_TESTSAFEMODE = false;
131 static const bool DEFAULT_ENABLE_REPLACEMENT = false;
132 
134 static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;
135 
137 {
138  size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); }
139 };
140 
141 extern CScript COINBASE_FLAGS;
143 extern CTxMemPool mempool;
144 typedef boost::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
145 extern BlockMap mapBlockIndex;
146 extern uint64_t nLastBlockTx;
147 extern uint64_t nLastBlockSize;
148 extern const std::string strMessageMagic;
151 extern bool fImporting;
152 extern bool fReindex;
153 extern int nScriptCheckThreads;
154 extern bool fTxIndex;
155 extern bool fIsBareMultisigStd;
156 extern bool fRequireStandard;
157 extern unsigned int nBytesPerSigOp;
158 extern bool fCheckBlockIndex;
159 extern bool fCheckpointsEnabled;
160 extern size_t nCoinCacheUsage;
161 extern CFeeRate minRelayTxFee;
162 extern bool fAlerts;
163 extern bool fEnableReplacement;
164 
165 extern std::map<uint256, int64_t> mapRejectedBlocks;
166 
167 static const int DIP0001_PROTOCOL_VERSION = 70208;
168 extern std::atomic<bool> fDIP0001WasLockedIn;
169 extern std::atomic<bool> fDIP0001ActiveAtTip;
170 
172 extern uint256 hashAssumeValid;
173 
176 
178 static const uint64_t nMinDiskSpace = 52428800;
179 
182 extern bool fHavePruned;
184 extern bool fPruneMode;
186 extern uint64_t nPruneTarget;
188 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
189 
190 static const signed int DEFAULT_CHECKBLOCKS = MIN_BLOCKS_TO_KEEP;
191 static const unsigned int DEFAULT_CHECKLEVEL = 3;
192 
193 // Require that user allocate at least 945MB for block & undo files (blk???.dat and rev???.dat)
194 // At 2MB per block, 288 blocks = 576MB.
195 // Add 15% for Undo data = 662MB
196 // Add 20% for Orphan block rate = 794MB
197 // We want the low water mark after pruning to be at least 794 MB and since we prune in
198 // full block file chunks, we need the high water mark which triggers the prune to be
199 // one 128MB block file + added 15% undo data = 147MB greater for a total of 941MB
200 // Setting the target to > than 945MB will make it likely we can respect the target.
201 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 945 * 1024 * 1024;
202 
221 bool ProcessNewBlock(const CChainParams& chainparams, const CBlock* pblock, bool fForceProcessing, const CDiskBlockPos* dbp, bool* fNewBlock);
222 
231 bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex=NULL);
232 
234 bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
236 FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
238 FILE* OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly = false);
240 boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix);
242 bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp = NULL);
244 bool InitBlockIndex(const CChainParams& chainparams);
246 bool LoadBlockIndex();
248 void UnloadBlockIndex();
250 void ThreadScriptCheck();
260 std::string GetWarnings(const std::string& strFor);
262 bool GetTransaction(const uint256 &hash, CTransaction &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false);
264 bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, const CBlock* pblock = NULL);
265 
266 double ConvertBitsToDouble(unsigned int nBits);
267 CAmount GetBlockSubsidy(int nBits, int nHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly = false);
268 CAmount GetMasternodePayment(int nHeight, CAmount blockValue);
269 
285 void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight);
286 
290 void UnlinkPrunedFiles(std::set<int>& setFilesToPrune);
291 
295 void FlushStateToDisk();
297 void PruneAndFlush();
298 
300 bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,
301  bool* pfMissingInputs, bool fOverrideMempoolLimit=false, bool fRejectAbsurdFee=false, bool fDryRun=false);
302 
303 bool GetUTXOCoins(const COutPoint& outpoint, CCoins& coins);
304 int GetUTXOHeight(const COutPoint& outpoint);
305 int GetUTXOConfirmations(const COutPoint& outpoint);
306 
308 std::string FormatStateMessage(const CValidationState &state);
309 
312 
314  unsigned int timestamp;
315 
316  size_t GetSerializeSize(int nType, int nVersion) const {
317  return 4;
318  }
319  template<typename Stream>
320  void Serialize(Stream& s, int nType, int nVersion) const {
322  }
323  template<typename Stream>
324  void Unserialize(Stream& s, int nType, int nVersion) {
326  }
327 
328  CTimestampIndexIteratorKey(unsigned int time) {
329  timestamp = time;
330  }
331 
333  SetNull();
334  }
335 
336  void SetNull() {
337  timestamp = 0;
338  }
339 };
340 
342  unsigned int timestamp;
344 
345  size_t GetSerializeSize(int nType, int nVersion) const {
346  return 36;
347  }
348  template<typename Stream>
349  void Serialize(Stream& s, int nType, int nVersion) const {
351  blockHash.Serialize(s, nType, nVersion);
352  }
353  template<typename Stream>
354  void Unserialize(Stream& s, int nType, int nVersion) {
356  blockHash.Unserialize(s, nType, nVersion);
357  }
358 
359  CTimestampIndexKey(unsigned int time, uint256 hash) {
360  timestamp = time;
361  blockHash = hash;
362  }
363 
365  SetNull();
366  }
367 
368  void SetNull() {
369  timestamp = 0;
370  blockHash.SetNull();
371  }
372 };
373 
375  unsigned int type;
378  size_t index;
379 
380  size_t GetSerializeSize(int nType, int nVersion) const {
381  return 57;
382  }
383  template<typename Stream>
384  void Serialize(Stream& s, int nType, int nVersion) const {
385  ser_writedata8(s, type);
386  hashBytes.Serialize(s, nType, nVersion);
387  txhash.Serialize(s, nType, nVersion);
389  }
390  template<typename Stream>
391  void Unserialize(Stream& s, int nType, int nVersion) {
392  type = ser_readdata8(s);
393  hashBytes.Unserialize(s, nType, nVersion);
394  txhash.Unserialize(s, nType, nVersion);
395  index = ser_readdata32(s);
396  }
397 
398  CAddressUnspentKey(unsigned int addressType, uint160 addressHash, uint256 txid, size_t indexValue) {
399  type = addressType;
400  hashBytes = addressHash;
401  txhash = txid;
402  index = indexValue;
403  }
404 
406  SetNull();
407  }
408 
409  void SetNull() {
410  type = 0;
411  hashBytes.SetNull();
412  txhash.SetNull();
413  index = 0;
414  }
415 };
416 
421 
423 
424  template <typename Stream, typename Operation>
425  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
429  }
430 
431  CAddressUnspentValue(CAmount sats, CScript scriptPubKey, int height) {
432  satoshis = sats;
433  script = scriptPubKey;
434  blockHeight = height;
435  }
436 
438  SetNull();
439  }
440 
441  void SetNull() {
442  satoshis = -1;
443  script.clear();
444  blockHeight = 0;
445  }
446 
447  bool IsNull() const {
448  return (satoshis == -1);
449  }
450 };
451 
453  unsigned int type;
456  unsigned int txindex;
458  size_t index;
459  bool spending;
460 
461  size_t GetSerializeSize(int nType, int nVersion) const {
462  return 66;
463  }
464  template<typename Stream>
465  void Serialize(Stream& s, int nType, int nVersion) const {
466  ser_writedata8(s, type);
467  hashBytes.Serialize(s, nType, nVersion);
468  // Heights are stored big-endian for key sorting in LevelDB
471  txhash.Serialize(s, nType, nVersion);
473  char f = spending;
474  ser_writedata8(s, f);
475  }
476  template<typename Stream>
477  void Unserialize(Stream& s, int nType, int nVersion) {
478  type = ser_readdata8(s);
479  hashBytes.Unserialize(s, nType, nVersion);
482  txhash.Unserialize(s, nType, nVersion);
483  index = ser_readdata32(s);
484  char f = ser_readdata8(s);
485  spending = f;
486  }
487 
488  CAddressIndexKey(unsigned int addressType, uint160 addressHash, int height, int blockindex,
489  uint256 txid, size_t indexValue, bool isSpending) {
490  type = addressType;
491  hashBytes = addressHash;
492  blockHeight = height;
493  txindex = blockindex;
494  txhash = txid;
495  index = indexValue;
496  spending = isSpending;
497  }
498 
500  SetNull();
501  }
502 
503  void SetNull() {
504  type = 0;
505  hashBytes.SetNull();
506  blockHeight = 0;
507  txindex = 0;
508  txhash.SetNull();
509  index = 0;
510  spending = false;
511  }
512 
513 };
514 
516  unsigned int type;
518 
519  size_t GetSerializeSize(int nType, int nVersion) const {
520  return 21;
521  }
522  template<typename Stream>
523  void Serialize(Stream& s, int nType, int nVersion) const {
524  ser_writedata8(s, type);
525  hashBytes.Serialize(s, nType, nVersion);
526  }
527  template<typename Stream>
528  void Unserialize(Stream& s, int nType, int nVersion) {
529  type = ser_readdata8(s);
530  hashBytes.Unserialize(s, nType, nVersion);
531  }
532 
533  CAddressIndexIteratorKey(unsigned int addressType, uint160 addressHash) {
534  type = addressType;
535  hashBytes = addressHash;
536  }
537 
539  SetNull();
540  }
541 
542  void SetNull() {
543  type = 0;
544  hashBytes.SetNull();
545  }
546 };
547 
549  unsigned int type;
552 
553  size_t GetSerializeSize(int nType, int nVersion) const {
554  return 25;
555  }
556  template<typename Stream>
557  void Serialize(Stream& s, int nType, int nVersion) const {
558  ser_writedata8(s, type);
559  hashBytes.Serialize(s, nType, nVersion);
561  }
562  template<typename Stream>
563  void Unserialize(Stream& s, int nType, int nVersion) {
564  type = ser_readdata8(s);
565  hashBytes.Unserialize(s, nType, nVersion);
567  }
568 
569  CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, int height) {
570  type = addressType;
571  hashBytes = addressHash;
572  blockHeight = height;
573  }
574 
576  SetNull();
577  }
578 
579  void SetNull() {
580  type = 0;
581  hashBytes.SetNull();
582  blockHeight = 0;
583  }
584 };
585 
586 struct CDiskTxPos : public CDiskBlockPos
587 {
588  unsigned int nTxOffset; // after header
589 
591 
592  template <typename Stream, typename Operation>
593  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
594  READWRITE(*(CDiskBlockPos*)this);
596  }
597 
598  CDiskTxPos(const CDiskBlockPos &blockIn, unsigned int nTxOffsetIn) : CDiskBlockPos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) {
599  }
600 
602  SetNull();
603  }
604 
605  void SetNull() {
607  nTxOffset = 0;
608  }
609 };
610 
611 
617 unsigned int GetLegacySigOpCount(const CTransaction& tx);
618 
626 unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& mapInputs);
627 
628 
634 bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &view, bool fScriptChecks,
635  unsigned int flags, bool cacheStore, std::vector<CScriptCheck> *pvChecks = NULL);
636 
638 void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCache &inputs, int nHeight);
639 
641 bool CheckTransaction(const CTransaction& tx, CValidationState& state);
642 
647 bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime);
648 
656 bool CheckFinalTx(const CTransaction &tx, int flags = -1);
657 
661 bool TestLockPointValidity(const LockPoints* lp);
662 
667 bool SequenceLocks(const CTransaction &tx, int flags, std::vector<int>* prevHeights, const CBlockIndex& block);
668 
680 bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = NULL, bool useExistingLockPoints = false);
681 
687 {
688 private:
691  unsigned int nIn;
692  unsigned int nFlags;
695 
696 public:
698  CScriptCheck(const CCoins& txFromIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn) :
699  scriptPubKey(txFromIn.vout[txToIn.vin[nInIn].prevout.n].scriptPubKey),
700  ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR) { }
701 
702  bool operator()();
703 
704  void swap(CScriptCheck &check) {
706  std::swap(ptxTo, check.ptxTo);
707  std::swap(nIn, check.nIn);
708  std::swap(nFlags, check.nFlags);
709  std::swap(cacheStore, check.cacheStore);
710  std::swap(error, check.error);
711  }
712 
713  ScriptError GetScriptError() const { return error; }
714 };
715 
716 bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector<uint256> &hashes);
718 bool GetAddressIndex(uint160 addressHash, int type,
719  std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
720  int start = 0, int end = 0);
721 bool GetAddressUnspent(uint160 addressHash, int type,
722  std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs);
723 
725 bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart);
726 bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams);
727 bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams);
728 
735 bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockIndex* pindex, CCoinsViewCache& coins, bool* pfClean = NULL);
736 
738 bool DisconnectBlocks(int blocks);
739 void ReprocessBlocks(int nBlocks);
740 
742 bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false);
743 
745 bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true);
746 bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
747 
749 bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex *pindexPrev);
750 bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIndex *pindexPrev);
751 
753 bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
754 
755 
757 {
758 public:
759  unsigned int nBlocks;
760  unsigned int nSize;
761  unsigned int nUndoSize;
762  unsigned int nHeightFirst;
763  unsigned int nHeightLast;
764  uint64_t nTimeFirst;
765  uint64_t nTimeLast;
766 
768 
769  template <typename Stream, typename Operation>
770  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
778  }
779 
780  void SetNull() {
781  nBlocks = 0;
782  nSize = 0;
783  nUndoSize = 0;
784  nHeightFirst = 0;
785  nHeightLast = 0;
786  nTimeFirst = 0;
787  nTimeLast = 0;
788  }
789 
791  SetNull();
792  }
793 
794  std::string ToString() const;
795 
797  void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn) {
798  if (nBlocks==0 || nHeightFirst > nHeightIn)
799  nHeightFirst = nHeightIn;
800  if (nBlocks==0 || nTimeFirst > nTimeIn)
801  nTimeFirst = nTimeIn;
802  nBlocks++;
803  if (nHeightIn > nHeightLast)
804  nHeightLast = nHeightIn;
805  if (nTimeIn > nTimeLast)
806  nTimeLast = nTimeIn;
807  }
808 };
809 
811 class CVerifyDB {
812 public:
813  CVerifyDB();
814  ~CVerifyDB();
815  bool VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth);
816 };
817 
819 CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator);
820 
822 bool InvalidateBlock(CValidationState& state, const Consensus::Params& consensusParams, CBlockIndex *pindex);
823 
825 bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex);
826 
828 extern CChain chainActive;
829 
831 extern CCoinsViewCache *pcoinsTip;
832 
834 extern CBlockTreeDB *pblocktree;
835 
841 int GetSpendHeight(const CCoinsViewCache& inputs);
842 
844 
848 int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params, bool fAssumeMasternodeIsUpgraded = false);
849 
854 bool GetBlockHash(uint256& hashRet, int nBlockHeight = -1);
855 
860 static const unsigned int REJECT_INTERNAL = 0x100;
862 static const unsigned int REJECT_HIGHFEE = 0x100;
864 static const unsigned int REJECT_ALREADY_KNOWN = 0x101;
866 static const unsigned int REJECT_CONFLICT = 0x102;
867 
868 #endif // BITCOIN_VALIDATION_H
bool cacheStore
Definition: validation.h:693
#define VARINT(obj)
Definition: serialize.h:388
static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT
Definition: validation.h:68
CTxMemPool mempool
static const int DEFAULT_SCRIPTCHECK_THREADS
Definition: validation.h:85
bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints *lp=NULL, bool useExistingLockPoints=false)
Definition: validation.cpp:346
void FlushStateToDisk()
bool InvalidateBlock(CValidationState &state, const Consensus::Params &consensusParams, CBlockIndex *pindex)
size_t nCoinCacheUsage
Definition: validation.cpp:83
void SetNull()
Definition: chain.h:47
static const unsigned int MAX_BLOCKFILE_SIZE
Definition: validation.h:76
static const unsigned int DEFAULT_DESCENDANT_LIMIT
Definition: validation.h:70
double ConvertBitsToDouble(unsigned int nBits)
CTimestampIndexKey(unsigned int time, uint256 hash)
Definition: validation.h:359
void UpdateCoins(const CTransaction &tx, CValidationState &state, CCoinsViewCache &inputs, int nHeight)
boost::condition_variable CConditionVariable
Definition: sync.h:84
Definition: coins.h:73
static const bool DEFAULT_PERMIT_BAREMULTISIG
Definition: validation.h:120
size_t GetSerializeSize(int nType, int nVersion) const
Definition: validation.h:380
uint160 hashBytes
Definition: validation.h:454
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn)
Definition: validation.h:797
void Unserialize(Stream &s, int nType, int nVersion)
Definition: validation.h:528
ADD_SERIALIZE_METHODS
Definition: validation.h:590
void SetNull()
Definition: uint256.h:41
uint64_t nTimeLast
earliest time of block in file
Definition: validation.h:765
void Serialize(Stream &s, int nType, int nVersion) const
Definition: uint256.h:86
static const unsigned int AVG_ADDRESS_BROADCAST_INTERVAL
Definition: validation.h:107
enum ScriptError_t ScriptError
CScriptCheck(const CCoins &txFromIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn)
Definition: validation.h:698
uint64_t nTimeFirst
highest height of block in file
Definition: validation.h:764
uint8_t ser_readdata8(Stream &s)
Definition: serialize.h:105
#define READWRITE(obj)
Definition: serialize.h:175
CConditionVariable cvBlockChange
Definition: validation.cpp:68
void Unserialize(Stream &s, int nType, int nVersion)
Definition: validation.h:354
void Serialize(Stream &s, int nType, int nVersion) const
Definition: validation.h:557
bool fTxIndex
Definition: validation.cpp:72
static const unsigned int AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL
Definition: validation.h:105
bool ContextualCheckBlockHeader(const CBlockHeader &block, CValidationState &state, CBlockIndex *pindexPrev)
bool WriteBlockToDisk(const CBlock &block, CDiskBlockPos &pos, const CMessageHeader::MessageStartChars &messageStart)
static const unsigned int DEFAULT_DIP0001_MIN_RELAY_TX_FEE
Definition: validation.h:62
unsigned int type
Definition: validation.h:375
static const unsigned int REJECT_ALREADY_KNOWN
Definition: validation.h:864
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE
Definition: validation.h:112
CAddressIndexKey(unsigned int addressType, uint160 addressHash, int height, int blockindex, uint256 txid, size_t indexValue, bool isSpending)
Definition: validation.h:488
CBlockIndex * pindexBestHeader
Definition: validation.cpp:66
static const unsigned int MIN_BLOCKS_TO_KEEP
Definition: validation.h:188
static const unsigned int DEFAULT_ANCESTOR_LIMIT
Definition: validation.h:66
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
Definition: validation.cpp:200
void ReprocessBlocks(int nBlocks)
const char * prefix
Definition: rest.cpp:600
static const unsigned int REJECT_CONFLICT
Definition: validation.h:866
static const unsigned int MAX_REJECT_MESSAGE_LENGTH
Definition: validation.h:103
unsigned int nUndoSize
number of used bytes of block file
Definition: validation.h:761
void ser_writedata32(Stream &s, uint32_t obj)
Definition: serialize.h:90
CBlockIndex * FindForkInGlobalIndex(const CChain &chain, const CBlockLocator &locator)
Definition: validation.cpp:172
std::string ToString() const
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: validation.h:425
sph_u32 high
Definition: keccak.c:370
bool GetTransaction(const uint256 &hash, CTransaction &tx, const Consensus::Params &params, uint256 &hashBlock, bool fAllowSlow=false)
bool LoadExternalBlockFile(const CChainParams &chainparams, FILE *fileIn, CDiskBlockPos *dbp=NULL)
bool IsNull() const
Definition: validation.h:447
CCoinsViewCache * pcoinsTip
Definition: validation.cpp:187
Definition: net.h:108
BlockMap mapBlockIndex
Definition: validation.cpp:64
bool CheckTransaction(const CTransaction &tx, CValidationState &state)
Definition: validation.cpp:470
CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, int height)
Definition: validation.h:569
unsigned int GetLegacySigOpCount(const CTransaction &tx)
Definition: validation.cpp:417
int flags
Definition: dash-tx.cpp:326
static const unsigned int DEFAULT_LIMITFREERELAY
Definition: validation.h:116
CAddressUnspentValue(CAmount sats, CScript scriptPubKey, int height)
Definition: validation.h:431
bool operator()()
CAddressUnspentKey(unsigned int addressType, uint160 addressHash, uint256 txid, size_t indexValue)
Definition: validation.h:398
ScriptError error
Definition: validation.h:694
ThresholdState
Definition: versionbits.h:20
bool ReconsiderBlock(CValidationState &state, CBlockIndex *pindex)
static const uint64_t nMinDiskSpace
Definition: validation.h:178
void Unserialize(Stream &s, int nType, int nVersion)
Definition: validation.h:477
size_t GetSerializeSize(int nType, int nVersion) const
Definition: validation.h:553
bool LoadBlockIndex()
bool ContextualCheckBlock(const CBlock &block, CValidationState &state, CBlockIndex *pindexPrev)
void Serialize(Stream &s, int nType, int nVersion) const
Definition: validation.h:384
boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix)
bool CheckFinalTx(const CTransaction &tx, int flags=-1)
Definition: validation.cpp:213
static const bool DEFAULT_ADDRESSINDEX
Definition: validation.h:124
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS
Definition: validation.h:64
bool fEnableReplacement
Definition: validation.cpp:86
CCriticalSection cs_main
Definition: validation.cpp:62
unsigned int nSize
number of blocks stored in file
Definition: validation.h:760
DeploymentPos
Definition: params.h:15
bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
static const unsigned int REJECT_INTERNAL
Definition: validation.h:860
int64_t CAmount
Definition: amount.h:14
unsigned int nBytesPerSigOp
Definition: validation.cpp:80
bool TestBlockValidity(CValidationState &state, const CChainParams &chainparams, const CBlock &block, CBlockIndex *pindexPrev, bool fCheckPOW=true, bool fCheckMerkleRoot=true)
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
unsigned int txindex
Definition: validation.h:456
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER
Definition: validation.h:114
void SetNull()
Definition: validation.h:605
static const bool DEFAULT_ALERTS
Definition: validation.h:51
static const unsigned int AVG_INVENTORY_BROADCAST_INTERVAL
Definition: validation.h:110
static const bool DEFAULT_WHITELISTRELAY
Definition: validation.h:53
size_t GetSerializeSize(int nType, int nVersion) const
Definition: validation.h:461
ADD_SERIALIZE_METHODS
latest time of block in file
Definition: validation.h:767
uint32_t ser_readdata32(Stream &s)
Definition: serialize.h:117
void swap(prevector< N, T, Size, Diff > &other)
Definition: prevector.h:410
static const unsigned int BLOCKFILE_CHUNK_SIZE
Definition: validation.h:78
unsigned int nHeightLast
lowest height of block in file
Definition: validation.h:763
unsigned int timestamp
Definition: validation.h:342
void Serialize(Stream &s, int nType, int nVersion) const
Definition: validation.h:320
bool fHavePruned
Definition: validation.cpp:76
bool ActivateBestChain(CValidationState &state, const CChainParams &chainparams, const CBlock *pblock=NULL)
static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER
Definition: validation.h:87
size_t GetSerializeSize(int nType, int nVersion) const
Definition: validation.h:316
static const unsigned int DEFAULT_BYTES_PER_SIGOP
Definition: validation.h:121
bool GetUTXOCoins(const COutPoint &outpoint, CCoins &coins)
Definition: validation.cpp:446
bool SequenceLocks(const CTransaction &tx, int flags, std::vector< int > *prevHeights, const CBlockIndex &block)
Definition: validation.cpp:323
static const unsigned int MAX_HEADERS_RESULTS
Definition: validation.h:92
bool fAlerts
Definition: validation.cpp:85
void swap(CScriptCheck &check)
Definition: validation.h:704
const CTransaction * ptxTo
Definition: validation.h:690
Definition: chain.h:355
static const unsigned int UNDOFILE_CHUNK_SIZE
Definition: validation.h:80
std::atomic< bool > fDIP0001ActiveAtTip
Definition: validation.cpp:89
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT
Definition: validation.h:72
static const unsigned int DEFAULT_MEMPOOL_EXPIRY
Definition: validation.h:74
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: validation.h:593
bool TestLockPointValidity(const LockPoints *lp)
Definition: validation.cpp:328
CDiskTxPos(const CDiskBlockPos &blockIn, unsigned int nTxOffsetIn)
Definition: validation.h:598
std::string GetWarnings(const std::string &strFor)
ThresholdState VersionBitsTipState(const Consensus::Params &params, Consensus::DeploymentPos pos)
void ser_writedata32be(Stream &s, uint32_t obj)
Definition: serialize.h:95
bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector< uint256 > &hashes)
std::string FormatStateMessage(const CValidationState &state)
Definition: validation.cpp:541
bool ConnectBlock(const CBlock &block, CValidationState &state, CBlockIndex *pindex, CCoinsViewCache &coins, bool fJustCheck=false)
int nFile
Definition: chain.h:19
bool ProcessNewBlock(const CChainParams &chainparams, const CBlock *pblock, bool fForceProcessing, const CDiskBlockPos *dbp, bool *fNewBlock)
void Serialize(Stream &s, int nType, int nVersion) const
Definition: validation.h:349
bool InitBlockIndex(const CChainParams &chainparams)
static const unsigned int DATABASE_WRITE_INTERVAL
Definition: validation.h:99
bool GetAddressUnspent(uint160 addressHash, int type, std::vector< std::pair< CAddressUnspentKey, CAddressUnspentValue > > &unspentOutputs)
int GetUTXOHeight(const COutPoint &outpoint)
Definition: validation.cpp:454
unsigned int nPos
Definition: chain.h:20
uint64_t nPruneTarget
Definition: validation.cpp:84
void Serialize(Stream &s, int nType, int nVersion) const
Definition: validation.h:465
bool fImporting
Definition: validation.cpp:70
bool fReindex
Definition: validation.cpp:71
unsigned int nTxOffset
Definition: validation.h:588
bool DisconnectBlock(const CBlock &block, CValidationState &state, const CBlockIndex *pindex, CCoinsViewCache &coins, bool *pfClean=NULL)
uint64_t nLastBlockSize
Definition: miner.cpp:49
CFeeRate minRelayTxFee
Definition: validation.cpp:94
CChain chainActive
Definition: validation.cpp:65
bool GetBlockHash(uint256 &hashRet, int nBlockHeight=-1)
void UnlinkPrunedFiles(std::set< int > &setFilesToPrune)
static const bool DEFAULT_CHECKPOINTS_ENABLED
Definition: validation.h:122
static const bool DEFAULT_ENABLE_REPLACEMENT
Definition: validation.h:131
std::map< uint256, int64_t > mapRejectedBlocks
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params, bool fAssumeMasternodeIsUpgraded=false)
static const bool DEFAULT_TESTSAFEMODE
Definition: validation.h:129
FILE * OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly=false)
void Unserialize(Stream &s, int nType, int nVersion)
Definition: validation.h:563
unsigned int nBlocks
Definition: validation.h:759
bool CheckBlock(const CBlock &block, CValidationState &state, bool fCheckPOW=true, bool fCheckMerkleRoot=true)
CWaitableCriticalSection csBestBlock
Definition: validation.cpp:67
void FindFilesToPrune(std::set< int > &setFilesToPrune, uint64_t nPruneAfterHeight)
bool fRequireStandard
Definition: validation.cpp:79
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: validation.h:770
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:32
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:190
boost::unordered_map< uint256, CBlockIndex *, BlockHasher > BlockMap
Definition: validation.h:144
std::atomic< bool > fDIP0001WasLockedIn
Definition: validation.cpp:88
uint256 hashAssumeValid
Definition: validation.cpp:91
bool CheckDiskSpace(uint64_t nAdditionalBytes=0)
static const bool DEFAULT_TIMESTAMPINDEX
Definition: validation.h:125
uint32_t ser_readdata32be(Stream &s)
Definition: serialize.h:123
sph_u32 low
Definition: keccak.c:370
CAmount GetBlockSubsidy(int nBits, int nHeight, const Consensus::Params &consensusParams, bool fSuperblockPartOnly=false)
unsigned int nIn
Definition: validation.h:691
static const unsigned int MAX_BLOCKS_TO_ANNOUNCE
Definition: validation.h:134
bool CheckInputs(const CTransaction &tx, CValidationState &state, const CCoinsViewCache &view, bool fScriptChecks, unsigned int flags, bool cacheStore, std::vector< CScriptCheck > *pvChecks=NULL)
void PruneAndFlush()
CBlockIndex * InsertBlockIndex(uint256 hash)
Definition: protocol.h:314
size_t operator()(const uint256 &hash) const
Definition: validation.h:138
void SetNull()
Definition: validation.h:780
CTimestampIndexIteratorKey(unsigned int time)
Definition: validation.h:328
void ThreadScriptCheck()
bool fIsBareMultisigStd
Definition: validation.cpp:78
bool IsInitialBlockDownload()
CScript scriptPubKey
Definition: validation.h:689
bool VerifyDB(const CChainParams &chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
CScript COINBASE_FLAGS
Definition: validation.cpp:107
size_t GetSerializeSize(int nType, int nVersion) const
Definition: validation.h:345
static const unsigned int DEFAULT_BANSCORE_THRESHOLD
Definition: validation.h:127
static const int DIP0001_PROTOCOL_VERSION
Definition: validation.h:167
ScriptError GetScriptError() const
Definition: validation.h:713
static const bool DEFAULT_SPENTINDEX
Definition: validation.h:126
bool DisconnectBlocks(int blocks)
static const unsigned int BLOCK_STALLING_TIMEOUT
Definition: validation.h:89
int nScriptCheckThreads
Definition: validation.cpp:69
void Unserialize(Stream &s, int nType, int nVersion)
Definition: validation.h:324
void clear()
Definition: script.h:639
void Unserialize(Stream &s, int nType, int nVersion)
Definition: uint256.h:92
bool fPruneMode
Definition: validation.cpp:77
static const unsigned int DEFAULT_LEGACY_MIN_RELAY_TX_FEE
Definition: validation.h:61
unsigned int nHeightFirst
number of used bytes in the undo file
Definition: validation.h:762
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Definition: validation.h:201
int GetUTXOConfirmations(const COutPoint &outpoint)
Definition: validation.cpp:461
static const unsigned int DATABASE_FLUSH_INTERVAL
Definition: validation.h:101
int GetSpendHeight(const CCoinsViewCache &inputs)
size_t GetSerializeSize(int nType, int nVersion) const
Definition: validation.h:519
uint64_t GetCheapHash() const
Definition: uint256.h:125
const std::string strMessageMagic
Definition: validation.cpp:109
bool fCheckpointsEnabled
Definition: validation.cpp:82
Definition: block.h:73
CAddressIndexIteratorKey(unsigned int addressType, uint160 addressHash)
Definition: validation.h:533
bool GetAddressIndex(uint160 addressHash, int type, std::vector< std::pair< CAddressIndexKey, CAmount > > &addressIndex, int start=0, int end=0)
static const bool DEFAULT_RELAYPRIORITY
Definition: validation.h:117
CAmount GetMasternodePayment(int nHeight, CAmount blockValue)
FILE * OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly=false)
void Serialize(Stream &s, int nType, int nVersion) const
Definition: validation.h:523
static const bool DEFAULT_WHITELISTFORCERELAY
Definition: validation.h:55
void Unserialize(Stream &s, int nType, int nVersion)
Definition: validation.h:391
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, bool *pfMissingInputs, bool fOverrideMempoolLimit=false, bool fRejectAbsurdFee=false, bool fDryRun=false)
VersionBitsCache versionbitscache
uint64_t nLastBlockTx
Definition: miner.cpp:48
CBlockTreeDB * pblocktree
Definition: validation.cpp:188
unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Definition: validation.cpp:431
static const bool DEFAULT_TXINDEX
Definition: validation.h:123
void UnloadBlockIndex()
static const unsigned int BLOCK_DOWNLOAD_WINDOW
Definition: validation.h:97
static const unsigned int DEFAULT_CHECKLEVEL
Definition: validation.h:191
void ser_writedata8(Stream &s, uint8_t obj)
Definition: serialize.h:81
bool fCheckBlockIndex
Definition: validation.cpp:81
static const int MAX_SCRIPTCHECK_THREADS
Definition: validation.h:83
bool CheckBlockHeader(const CBlockHeader &block, CValidationState &state, bool fCheckPOW=true)
unsigned int type
Definition: validation.h:453
static const unsigned int REJECT_HIGHFEE
Definition: validation.h:862
bool ProcessNewBlockHeaders(const std::vector< CBlockHeader > &block, CValidationState &state, const CChainParams &chainparams, CBlockIndex **ppindex=NULL)
unsigned int nFlags
Definition: validation.h:692