Fabcoin Core  0.16.2
P2P Digital Currency
validation.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef FABCOIN_VALIDATION_H
7 #define FABCOIN_VALIDATION_H
8 
9 #if defined(HAVE_CONFIG_H)
10 #include <config/fabcoin-config.h>
11 #endif
12 
13 #include <amount.h>
14 #include <coins.h>
15 #include <fs.h>
16 #include <protocol.h> // For CMessageHeader::MessageStartChars
17 #include <policy/feerate.h>
18 #include <script/script_error.h>
19 #include <sync.h>
20 #include <versionbits.h>
21 
22 #include <algorithm>
23 #include <exception>
24 #include <map>
25 #include <set>
26 #include <stdint.h>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
31 #include <atomic>
32 
33 #include <boost/unordered_map.hpp>
34 #include <boost/filesystem/path.hpp>
35 #include <consensus/consensus.h>
36 #include <fasc/fascstate.h>
37 #include <fasc/fascDGP.h>
39 #include <libethashseal/Ethash.h>
41 #include <script/standard.h>
42 #include <fasc/storageresults.h>
43 extern std::unique_ptr<FascState> globalState;
44 extern std::shared_ptr<dev::eth::SealEngineFace> globalSealEngine;
45 extern bool fRecordLogOpcodes;
46 extern bool fIsVMlogFile;
47 extern bool fGettingValuesDGP;
49 using valtype = std::vector<unsigned char>;
50 using ExtractFascTX = std::pair<std::vector<FascTransaction>, std::vector<EthTransactionParams>>;
51 class CBlockIndex;
52 class CBlockTreeDB;
53 class CBloomFilter;
54 class CChainParams;
55 class CCoinsViewDB;
56 class CInv;
57 class CConnman;
58 class CScriptCheck;
60 class CTxMemPool;
62 class CValidationState;
63 class CWallet;
64 struct CDiskTxPos;
65 struct ChainTxData;
66 
68 struct LockPoints;
69 
71 static const uint64_t MINIMUM_GAS_LIMIT = 10000;
72 static const uint64_t MEMPOOL_MIN_GAS_LIMIT = 22000;
74 static const bool DEFAULT_WHITELISTRELAY = true;
76 static const bool DEFAULT_WHITELISTFORCERELAY = true;
78 static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
80 
81 
83 static const CAmount DEFAULT_TRANSACTION_MAXFEE = 1 * COIN;
84 //?????? static const CAmount DEFAULT_TRANSACTION_MAXFEE = 0.1 * COIN;
86 static const CAmount HIGH_TX_FEE_PER_KB = 1 * COIN;
87 //??????? static const CAmount HIGH_TX_FEE_PER_KB = 0.01 * COIN;
89 static const CAmount HIGH_MAX_TX_FEE = 100 * HIGH_TX_FEE_PER_KB;
91 static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25;
93 static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
95 static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
97 static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
99 static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
101 static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20000;
103 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
105 static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
107 static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
108 
110 static const int MAX_SCRIPTCHECK_THREADS = 16;
112 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
114 static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
116 static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
119 static const unsigned int MAX_HEADERS_RESULTS = 2000;
122 static const int MAX_CMPCTBLOCK_DEPTH = 5;
124 static const int MAX_BLOCKTXN_DEPTH = 10;
129 static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
131 static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
133 static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
135 static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
137 static const unsigned int AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL = 24 * 60 * 60;
139 static const unsigned int AVG_ADDRESS_BROADCAST_INTERVAL = 30;
142 static const unsigned int INVENTORY_BROADCAST_INTERVAL = 5;
145 static const unsigned int INVENTORY_BROADCAST_MAX = 7 * INVENTORY_BROADCAST_INTERVAL;
147 static const unsigned int AVG_FEEFILTER_BROADCAST_INTERVAL = 10 * 60;
149 static const unsigned int MAX_FEEFILTER_CHANGE_DELAY = 5 * 60;
151 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000;
153 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000;
154 
155 //static const int64_t DEFAULT_MAX_TIP_AGE = 30 * 24 * 60 * 60; //fabcoin 30 days in case something causes the chain to get stuck in testnet
156 static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
158 static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60;
159 
161 static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
162 static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
163 static const bool DEFAULT_TXINDEX = false;
164 static const bool DEFAULT_LOGEVENTS = false;
165 static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
167 static const bool DEFAULT_PERSIST_MEMPOOL = true;
169 static const bool DEFAULT_ENABLE_REPLACEMENT = true;
171 static const bool DEFAULT_FEEFILTER = true;
172 
174 static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;
175 
177 static const int MAX_UNCONNECTING_HEADERS = 10;
178 
179 static const bool DEFAULT_PEERBLOOMFILTERS = true;
180 
182 static const int DEFAULT_STOPATHEIGHT = 0;
183 static const uint64_t DEFAULT_GAS_LIMIT_OP_CREATE=2500000;
184 static const uint64_t DEFAULT_GAS_LIMIT_OP_SEND=250000;
185 static const CAmount DEFAULT_GAS_PRICE=0.00000040*COIN;
186 static const CAmount MAX_RPC_GAS_PRICE=0.00000100*COIN;
187 static const size_t MAX_CONTRACT_VOUTS = 1000; // fasc
188 
190 {
191  size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); }
192 };
193 
194 extern CScript COINBASE_FLAGS;
197 extern CTxMemPool mempool;
198 typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
199 extern BlockMap mapBlockIndex;
200 extern uint64_t nLastBlockTx;
201 extern uint64_t nLastBlockWeight;
202 extern const std::string strMessageMagic;
205 extern std::atomic_bool fImporting;
206 extern bool fReindex;
207 extern bool fLogEvents;
208 extern int nScriptCheckThreads;
209 extern bool fTxIndex;
210 extern bool fIsBareMultisigStd;
211 extern bool fRequireStandard;
212 extern bool fCheckBlockIndex;
213 extern bool fCheckpointsEnabled;
214 extern size_t nCoinCacheUsage;
216 extern CFeeRate minRelayTxFee;
218 extern CAmount maxTxFee;
220 extern int64_t nMaxTipAge;
221 extern bool fEnableReplacement;
222 
224 extern uint256 hashAssumeValid;
225 
228 
231 
233 static const uint64_t nMinDiskSpace = 52428800;
234 
237 extern bool fHavePruned;
239 extern bool fPruneMode;
241 extern uint64_t nPruneTarget;
243 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
244 
245 static const signed int DEFAULT_CHECKBLOCKS = 6;
246 static const unsigned int DEFAULT_CHECKLEVEL = 3;
247 
248 // Require that user allocate at least 550MB for block & undo files (blk???.dat and rev???.dat)
249 // At 1MB per block, 288 blocks = 288MB.
250 // Add 15% for Undo data = 331MB
251 // Add 20% for Orphan block rate = 397MB
252 // We want the low water mark after pruning to be at least 397 MB and since we prune in
253 // full block file chunks, we need the high water mark which triggers the prune to be
254 // one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB
255 // Setting the target to > than 550MB will make it likely we can respect the target.
256 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
257 
258 inline int64_t FutureDrift(uint32_t nTime) { return nTime + 15; }
278 bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock);
279 
291 bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, CValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex=nullptr, CBlockHeader *first_invalid=nullptr);
292 
294 bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
296 FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
298 fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix);
300 bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp = nullptr);
302 bool InitBlockIndex(const CChainParams& chainparams);
304 bool LoadGenesisBlock(const CChainParams& chainparams);
307 bool LoadBlockIndex(const CChainParams& chainparams);
309 bool LoadChainTip(const CChainParams& chainparams);
311 void UnloadBlockIndex();
313 void ThreadScriptCheck();
323 std::string GetWarnings(const std::string& strFor);
325 bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false);
327 bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
328 CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
329 
331 double GuessVerificationProgress(const ChainTxData& data, CBlockIndex* pindex);
332 
336 void PruneOneBlockFile(const int fileNumber);
337 
341 void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune);
342 
346 bool FlushStateToDisk();
348 void PruneAndFlush();
350 void PruneBlockFilesManual(int nManualPruneHeight);
352 bool IsConfirmedInNPrevBlocks(const CDiskTxPos& txindex, const CBlockIndex* pindexFrom, int nMaxDepth, int& nActualDepth);
353 
356 bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
357  bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced = nullptr,
358  bool fOverrideMempoolLimit = false, const CAmount nAbsurdFee = 0, bool rawTx = false);
359 
361 bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
362  bool* pfMissingInputs, int64_t nAcceptTime, std::list<CTransactionRef>* plTxnReplaced = NULL,
363  bool fOverrideMempoolLimit = false, const CAmount nAbsurdFee = 0, bool rawTx = false);
364 
366 std::string FormatStateMessage(const CValidationState &state);
367 
370 
373 
376 
377 
379 void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
380 
383  unsigned int height;
384 
385  size_t GetSerializeSize(int nType, int nVersion) const {
386  return 4;
387  }
388  template<typename Stream>
389  void Serialize(Stream& s) const {
390  ser_writedata32be(s, height);
391  }
392  template<typename Stream>
393  void Unserialize(Stream& s) {
394  height = ser_readdata32be(s);
395  }
396 
397  CHeightTxIndexIteratorKey(unsigned int _height) {
398  height = _height;
399  }
400 
402  SetNull();
403  }
404 
405  void SetNull() {
406  height = 0;
407  }
408 };
409 
411  unsigned int height;
413 
414  size_t GetSerializeSize(int nType, int nVersion) const {
415  return 24;
416  }
417  template<typename Stream>
418  void Serialize(Stream& s) const {
419  ser_writedata32be(s, height);
420  s << address.asBytes();
421  }
422  template<typename Stream>
423  void Unserialize(Stream& s) {
424  height = ser_readdata32be(s);
425  valtype tmp;
426  s >> tmp;
427  address = dev::h160(tmp);
428  }
429 
430  CHeightTxIndexKey(unsigned int _height, dev::h160 _address) {
431  height = _height;
432  address = _address;
433  }
434 
436  SetNull();
437  }
438 
439  void SetNull() {
440  height = 0;
441  address.clear();
442  }
443 };
444 
446 
449 
455 unsigned int GetLegacySigOpCount(const CTransaction& tx);
463 unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& mapInputs);
464 
472 int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& inputs, int flags);
473 
479 bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &view, bool fScriptChecks,
480  unsigned int flags, bool cacheStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks = NULL);
481 
483 void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
484 
488 bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs);
489 
490 namespace Consensus {
491 
497 bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight);
498 
499 } // namespace Consensus
500 
504 bool CheckTransactionTimestamp(const CTransaction& tx, const uint32_t& nTimeBlock, CBlockTreeDB& txdb);
505 
510 bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime);
518 bool CheckFinalTx(const CTransaction &tx, int flags = -1);
519 
523 bool TestLockPointValidity(const LockPoints* lp);
524 bool SequenceLocks(const CTransaction &tx, int flags, std::vector<int>* prevHeights, const CBlockIndex& block);
525 
537 bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false);
538 
544 {
545 private:
549  unsigned int nIn;
550  unsigned int nFlags;
554 
555 public:
556  CScriptCheck(): amount(0), ptxTo(0), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
557  CScriptCheck(const CScript& scriptPubKeyIn, const CAmount amountIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
558  scriptPubKey(scriptPubKeyIn), amount(amountIn),
559  ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
560 
561  bool operator()();
562 
563  void swap(CScriptCheck &check) {
564  scriptPubKey.swap(check.scriptPubKey);
565  std::swap(ptxTo, check.ptxTo);
566  std::swap(amount, check.amount);
567  std::swap(nIn, check.nIn);
568  std::swap(nFlags, check.nFlags);
569  std::swap(cacheStore, check.cacheStore);
570  std::swap(error, check.error);
571  std::swap(txdata, check.txdata);
572  }
573 
574  ScriptError GetScriptError() const { return error; }
575 };
576 
579 
580 
582 //Template function that read the whole block or the header only depending on the type (CBlock or CBlockHeader)
583 template <typename Block>
584 bool ReadBlockFromDisk(Block& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams);
585 bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams);
586 bool ReadFromDisk(CBlockHeader& block, unsigned int nFile, unsigned int nBlockPos);
587 bool ReadFromDisk(CMutableTransaction& tx, CDiskTxPos& txindex, CBlockTreeDB& txdb, COutPoint prevout);
588 
592 bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
593 bool GetBlockPublicKey(const CBlock& block, std::vector<unsigned char>& vchPubKey);
594 bool SignBlock(std::shared_ptr<CBlock> pblock, CWallet& wallet, const CAmount& nTotalFees, uint32_t nTime);
595 bool CheckCanonicalBlockSignature(const std::shared_ptr<const CBlock> pblock);
596 bool CheckIndexProof(const CBlockIndex& block, const Consensus::Params& consensusParams);
600 bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev, int64_t nAdjustedTime);
601 
602 
604 bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
605 
607 bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
608 
610 bool RewindBlockIndex(const CChainParams& params);
611 
613 void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
614 
616 std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
617 
619 class CVerifyDB {
620 public:
621  CVerifyDB();
622  ~CVerifyDB();
623  bool VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth);
624 };
625 
627 bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
628 
630 CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator);
631 
633 bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex *pindex);
634 
636 bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex);
637 
639 bool ResetBlockFailureFlags(CBlockIndex *pindex);
640 
642 extern CChain chainActive;
643 
645 extern CCoinsViewDB *pcoinsdbview;
646 
648 extern CCoinsViewCache *pcoinsTip;
649 
651 extern CBlockTreeDB *pblocktree;
652 
659 int GetSpendHeight(const CCoinsViewCache& inputs);
660 
662 
666 int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params);
667 
672 static const unsigned int REJECT_INTERNAL = 0x100;
674 static const unsigned int REJECT_HIGHFEE = 0x100;
676 static const unsigned int REJECT_ALREADY_KNOWN = 0x101;
678 static const unsigned int REJECT_CONFLICT = 0x102;
679 
682 
684 void DumpMempool();
685 
687 bool LoadMempool();
688 
689 bool CheckReward(const CBlock& block, CValidationState& state, int nHeight, const Consensus::Params& consensusParams, CAmount nFees, CAmount gasRefunds, const std::vector<CTxOut>& vouts);
690 
692 std::vector<ResultExecute> CallContract(const dev::Address& addrContract, std::vector<unsigned char> opcode, const dev::Address& sender = dev::Address(), uint64_t gasLimit=0);
693 
694 bool CheckSenderScript(const CCoinsViewCache& view, const CTransaction& tx);
695 
696 bool CheckMinGasPrice(std::vector<EthTransactionParams>& etps, const uint64_t& minGasPrice);
697 
698 struct ByteCodeExecResult;
699 
700 void EnforceContractVoutLimit(ByteCodeExecResult& bcer, ByteCodeExecResult& bcerOut, const dev::h256& oldHashFascRoot,
701  const dev::h256& oldHashStateRoot, const std::vector<FascTransaction>& transactions);
702 
703 void writeVMlog(const std::vector<ResultExecute>& res, const CTransaction& tx = CTransaction(), const CBlock& block = CBlock());
704 
711 
713  if(this->version.toRaw() != etp.version.toRaw() || this->gasLimit != etp.gasLimit ||
714  this->gasPrice != etp.gasPrice || this->code != etp.code ||
715  this->receiveAddress != etp.receiveAddress)
716  return true;
717  return false;
718  }
719 };
720 
722  uint64_t usedGas = 0;
723  CAmount refundSender = 0;
724  std::vector<CTxOut> refundOutputs;
725  std::vector<CTransaction> valueTransfers;
726 };
727 
729 
730 public:
731 
732  FascTxConverter(CTransaction tx, CCoinsViewCache* v = NULL, const std::vector<CTransactionRef>* blockTxs = NULL) : txBit(tx), view(v), blockTransactions(blockTxs){}
733 
734  bool extractionFascTransactions(ExtractFascTX& fascTx);
735 
736 private:
737 
738  bool receiveStack(const CScript& scriptPubKey);
739 
740  bool parseEthTXParams(EthTransactionParams& params);
741 
742  FascTransaction createEthTX(const EthTransactionParams& etp, const uint32_t nOut);
743 
746  std::vector<valtype> stack;
748  const std::vector<CTransactionRef> *blockTransactions;
749 
750 };
751 
753 
754 public:
755 
756  ByteCodeExec(const CBlock& _block, std::vector<FascTransaction> _txs, const uint64_t _blockGasLimit) : txs(_txs), block(_block), blockGasLimit(_blockGasLimit) {}
757 
759 
760  bool processingResults(ByteCodeExecResult& result);
761 
762  std::vector<ResultExecute>& getResult(){ return result; }
763 
764 private:
765 
766  dev::eth::EnvInfo BuildEVMEnvironment();
767 
768  dev::Address EthAddrFromScript(const CScript& scriptIn);
769 
770  std::vector<FascTransaction> txs;
771 
772  std::vector<ResultExecute> result;
773 
774  const CBlock& block;
775 
776  const uint64_t blockGasLimit;
777 
778 };
780 #endif // FABCOIN_VALIDATION_H
CCoinsViewDB * pcoinsdbview
Global variable that points to the coins database (protected by cs_main)
Definition: validation.cpp:251
std::pair< std::vector< FascTransaction >, std::vector< EthTransactionParams >> ExtractFascTX
Definition: validation.h:50
void EnforceContractVoutLimit(ByteCodeExecResult &bcer, ByteCodeExecResult &bcerOut, const dev::h256 &oldHashFascRoot, const dev::h256 &oldHashStateRoot, const std::vector< FascTransaction > &transactions)
std::vector< ResultExecute > & getResult()
Definition: validation.h:762
CTxMemPool mempool
bool error(const char *fmt, const Args &...args)
Definition: util.h:178
size_t nCoinCacheUsage
Definition: validation.cpp:95
CAmount amount
Definition: validation.h:547
bool operator!=(EthTransactionParams etp)
Definition: validation.h:712
int64_t GetTransactionSigOpCost(const CTransaction &tx, const CCoinsViewCache &inputs, int flags)
Compute total signature operation cost of a transaction.
Definition: tx_verify.cpp:140
int64_t nMaxTipAge
If the tip is older than this (in seconds), the node is considered to be in initial block download...
Definition: validation.cpp:97
boost::condition_variable CConditionVariable
Just a typedef for boost::condition_variable, can be wrapped later if desired.
Definition: sync.h:103
bool CheckTxInputs(const CTransaction &tx, CValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight)
Check whether all inputs of this transaction are valid (no double spends and amounts) This does not m...
Definition: tx_verify.cpp:224
bool LoadExternalBlockFile(const CChainParams &chainparams, FILE *fileIn, CDiskBlockPos *dbp=nullptr)
Import blocks from an external file.
enum ScriptError_t ScriptError
Describes a place in the block chain to another node such that if the other node doesn&#39;t have the sam...
Definition: block.h:251
void PruneOneBlockFile(const int fileNumber)
Mark one block file as pruned.
CConditionVariable cvBlockChange
Definition: validation.cpp:83
bool CheckIndexProof(const CBlockIndex &block, const Consensus::Params &consensusParams)
bool fTxIndex
Definition: validation.cpp:87
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
Definition: Interface.h:284
void swap(CScriptCheck &check)
Definition: validation.h:563
Definition: block.h:155
const uint64_t blockGasLimit
Definition: validation.h:776
std::vector< ResultExecute > result
Definition: validation.h:772
An in-memory indexed chain of blocks.
Definition: chain.h:501
unsigned int nFlags
Definition: validation.h:550
void PruneBlockFilesManual(int nManualPruneHeight)
Prune block files up to a given height.
inv message data
Definition: protocol.h:338
void DumpMempool()
Dump the mempool to disk.
CBlockIndex * pindexBestHeader
Best header we&#39;ve seen so far (used for getheaders queries&#39; starting points).
Definition: validation.cpp:81
bool CheckSenderScript(const CCoinsViewCache &view, const CTransaction &tx)
bool CheckBlock(const CBlock &block, CValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW=true, bool fCheckMerkleRoot=true)
Functions for validating blocks and updating the block tree.
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
Check if transaction is final and can be included in a block with the specified height and time...
Definition: tx_verify.cpp:19
const char * prefix
Definition: rest.cpp:623
bool ResetBlockFailureFlags(CBlockIndex *pindex)
Remove invalidity status from a block and its descendants.
CBlockPolicyEstimator feeEstimator
Definition: validation.cpp:106
bool ProcessNewBlock(const CChainParams &chainparams, const std::shared_ptr< const CBlock > pblock, bool fForceProcessing, bool *fNewBlock)
Process an incoming block.
CBlockIndex * FindForkInGlobalIndex(const CChain &chain, const CBlockLocator &locator)
Find the last common block between the parameter chain and a locator.
Definition: validation.cpp:233
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
Definition: bloom.h:44
bool PreciousBlock(CValidationState &state, const CChainParams &params, CBlockIndex *pindex)
Mark a block as precious and reorganize.
CScript scriptPubKey
Definition: validation.h:546
std::vector< valtype > stack
Definition: validation.h:746
bool fIsVMlogFile
Definition: validation.cpp:73
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: validation.cpp:252
BlockMap mapBlockIndex
Definition: validation.cpp:79
unsigned int GetLegacySigOpCount(const CTransaction &tx)
Count ECDSA signature operations the old-fashioned (pre-0.6) way.
Definition: tx_verify.cpp:109
bool CheckTransactionTimestamp(const CTransaction &tx, const uint32_t &nTimeBlock, CBlockTreeDB &txdb)
Check if coinstake transaction timestamp is bigger than the previous.
bool ProcessNewBlockHeaders(const std::vector< CBlockHeader > &block, CValidationState &state, const CChainParams &chainparams, const CBlockIndex **ppindex=nullptr, CBlockHeader *first_invalid=nullptr)
Process incoming block headers.
bool fGettingValuesDGP
Definition: validation.cpp:74
ScriptError GetScriptError() const
Definition: validation.h:574
CChainParams defines various tweakable parameters of a given instance of the Fabcoin system...
Definition: chainparams.h:47
ScriptError error
Definition: validation.h:552
ThresholdState
Definition: versionbits.h:20
std::shared_ptr< dev::eth::SealEngineFace > globalSealEngine
Definition: validation.cpp:71
bool LoadMempool()
Load the mempool from disk.
bool cacheStore
Definition: validation.h:551
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:437
uint64_t GetCheapHash() const
A cheap hash function that just returns 64 bits from the result, it can be used when the contents are...
Definition: uint256.h:143
bool ActivateBestChain(CValidationState &state, const CChainParams &chainparams, std::shared_ptr< const CBlock > pblock=std::shared_ptr< const CBlock >())
Find the best known block, and make it the tip of the block chain.
bool CheckReward(const CBlock &block, CValidationState &state, int nHeight, const Consensus::Params &consensusParams, CAmount nFees, CAmount gasRefunds, const std::vector< CTxOut > &vouts)
BIP9Stats VersionBitsTipStatistics(const Consensus::Params &params, Consensus::DeploymentPos pos)
Get the numerical statistics for the BIP9 state for a given deployment at the current tip...
bool CheckFinalTx(const CTransaction &tx, int flags=-1)
Check if transaction will be final in the next block to be created.
Definition: validation.cpp:271
void Serialize(Stream &s) const
Definition: validation.h:389
bool fEnableReplacement
Definition: validation.cpp:98
CCriticalSection cs_main
Definition: validation.cpp:77
int64_t FutureDrift(uint32_t nTime)
Definition: validation.h:258
int64_t CAmount
Amount in lius (Can be negative)
Definition: amount.h:15
CHeightTxIndexIteratorKey(unsigned int _height)
Definition: validation.h:397
dev::h160 address
Definition: validation.h:412
ByteCodeExec(const CBlock &_block, std::vector< FascTransaction > _txs, const uint64_t _blockGasLimit)
Definition: validation.h:756
bool SignBlock(std::shared_ptr< CBlock > pblock, CWallet &wallet, const CAmount &nTotalFees, uint32_t nTime)
bool TestBlockValidity(CValidationState &state, const CChainParams &chainparams, const CBlock &block, CBlockIndex *pindexPrev, bool fCheckPOW=true, bool fCheckMerkleRoot=true)
Check a block is completely valid from start to finish (only works on top of our current best block...
opcodetype opcode
Definition: validation.h:747
bool InvalidateBlock(CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex)
Mark a block as invalid.
opcodetype
Script opcodes.
Definition: script.h:48
void UpdateUncommittedBlockStructures(CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams)
Update uncommitted block structures (currently: only the witness nonce).
void swap(prevector< N, T, Size, Diff > &other)
Definition: prevector.h:440
Access to the block database (blocks/index/)
Definition: txdb.h:116
std::vector< ResultExecute > CallContract(const dev::Address &addrContract, std::vector< unsigned char > opcode, const dev::Address &sender=dev::Address(), uint64_t gasLimit=0)
const std::vector< CTransactionRef > * blockTransactions
Definition: validation.h:748
bool ReadBlockFromDisk(Block &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
Abstract view on the open txout dataset.
Definition: coins.h:145
uint32_t toRaw()
DeploymentPos
Definition: params.h:15
bool CheckCanonicalBlockSignature(const std::shared_ptr< const CBlock > pblock)
bool fHavePruned
Pruning-related variables and constants.
Definition: validation.cpp:89
void InitScriptExecutionCache()
Initializes the script-execution cache.
We want to be able to estimate feerates that are needed on tx&#39;s to be included in a certain number of...
Definition: fees.h:162
CHeightTxIndexKey(unsigned int _height, dev::h160 _address)
Definition: validation.h:430
fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix)
Translation to a filesystem path.
bool SequenceLocks(const CTransaction &tx, int flags, std::vector< int > *prevHeights, const CBlockIndex &block)
Check if transaction is final per BIP 68 sequence numbers and can be included in a block...
Definition: tx_verify.cpp:104
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:619
bool AcceptToMemoryPoolWithTime(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, int64_t nAcceptTime, std::list< CTransactionRef > *plTxnReplaced=NULL, bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0, bool rawTx=false)
(try to) add transaction to memory pool with a specified acceptance time
bool LoadBlockIndex(const CChainParams &chainparams)
Load the block tree and coins database from disk, initializing state if we&#39;re running with -reindex...
size_t operator()(const uint256 &hash) const
Definition: validation.h:191
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
Definition: FixedHash.h:47
size_t GetSerializeSize(int nType, int nVersion) const
Definition: validation.h:385
dev::Address receiveAddress
Definition: validation.h:710
arith_uint256 nMinimumChainWork
Minimum work we will assume exists on some valid chain.
Definition: validation.cpp:101
bool TestLockPointValidity(const LockPoints *lp)
Test whether the LockPoints height and time are still valid on the current chain. ...
Definition: validation.cpp:303
std::string GetWarnings(const std::string &strFor)
Format a string that describes several potential problems detected by the core.
Definition: warnings.cpp:40
Definition: net.h:120
ThresholdState VersionBitsTipState(const Consensus::Params &params, Consensus::DeploymentPos pos)
Get the BIP9 state for a given deployment at the current tip.
std::atomic_bool fImporting
void ser_writedata32be(Stream &s, uint32_t obj)
Definition: serialize.h:84
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
Parameters that influence chain consensus.
Definition: params.h:39
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:18
std::string FormatStateMessage(const CValidationState &state)
Convert CValidationState to a human-readable message for logging.
Definition: validation.cpp:407
bool CheckInputs(const CTransaction &tx, CValidationState &state, const CCoinsViewCache &view, bool fScriptChecks, unsigned int flags, bool cacheStore, PrecomputedTransactionData &txdata, std::vector< CScriptCheck > *pvChecks=NULL)
Check whether all inputs of this transaction are valid (no double spends, scripts & sigs...
bool ReplayBlocks(const CChainParams &params, CCoinsView *view)
Replay blocks that aren&#39;t fully applied to the database.
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Determine what nVersion a new block should use.
bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params &params, uint256 &hashBlock, bool fAllowSlow=false)
Retrieve a transaction (from memory pool, or from disk, if possible)
256-bit unsigned big integer.
bool InitBlockIndex(const CChainParams &chainparams)
Initialize a new block tree database + block data on disk.
uint64_t nPruneTarget
Number of MiB of block files that we&#39;re trying to stay below.
Definition: validation.cpp:96
Closure representing one script verification Note that this stores references to the spending transac...
Definition: validation.h:543
bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints *lp=nullptr, bool useExistingLockPoints=false)
Check if transaction will be BIP 68 final in the next block to be created.
Definition: validation.cpp:321
StorageResults * pstorageresult
Definition: validation.cpp:254
bool fReindex
Definition: validation.cpp:86
bytes asBytes() const
Definition: FixedHash.h:145
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
Definition: validation.cpp:103
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:80
const CTransaction txBit
Definition: validation.h:744
bool RewindBlockIndex(const CChainParams &params)
When there are blocks in the active chain with missing data, rewind the chainstate and remove them fr...
Capture information about block/transaction validation.
Definition: validation.h:27
FascTxConverter(CTransaction tx, CCoinsViewCache *v=NULL, const std::vector< CTransactionRef > *blockTxs=NULL)
Definition: validation.h:732
256-bit opaque blob.
Definition: uint256.h:132
const CTransaction * ptxTo
Definition: validation.h:548
uint64_t nLastBlockWeight
Definition: miner.cpp:63
void clear()
Definition: FixedHash.h:217
CScriptCheck(const CScript &scriptPubKeyIn, const CAmount amountIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData *txdataIn)
Definition: validation.h:557
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:465
FILE * OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly=false)
Open a block file (blk?????.dat)
Template mixin that adds -Wthread-safety locking annotations to a subset of the mutex API...
Definition: sync.h:54
void Unserialize(Stream &s)
Definition: validation.h:393
PlatformStyle::TableColorType type
Definition: rpcconsole.cpp:61
CWaitableCriticalSection csBestBlock
Definition: validation.cpp:82
bool fRequireStandard
Definition: validation.cpp:92
bool ReadFromDisk(CBlockHeader &block, unsigned int nFile, unsigned int nBlockPos)
bool IsWitnessEnabled(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Check whether witness commitments are required for block.
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:177
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:417
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:74
CAmount maxTxFee
Absolute maximum transaction fee (in liu) used by wallet and mempool (rejects high fee in sendrawtran...
Definition: validation.cpp:104
size_t GetSerializeSize(int nType, int nVersion) const
Definition: validation.h:414
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, int nHeight)
Apply the effects of this transaction on the UTXO set represented by view.
uint256 hashAssumeValid
Block hash whose ancestors we will assume to have valid scripts without checking them.
Definition: validation.cpp:100
bool CheckDiskSpace(uint64_t nAdditionalBytes=0)
Check whether enough disk space is available for an incoming block.
uint32_t ser_readdata32be(Stream &s)
Definition: serialize.h:115
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:672
std::vector< unsigned char > GenerateCoinbaseCommitment(CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams)
Produce the necessary coinbase commitment for a block (modifies the hash, don&#39;t call for mined blocks...
const CCoinsViewCache * view
Definition: validation.h:745
void PruneAndFlush()
Prune block files and flush state to disk.
Fee rate in liu per kilobyte: CAmount / kB.
Definition: feerate.h:20
CBlockIndex * InsertBlockIndex(uint256 hash)
Create a new block index entry for a given block hash.
void ThreadScriptCheck()
Run an instance of the script checking thread.
unsigned int height
Definition: validation.h:411
bool fIsBareMultisigStd
Definition: validation.cpp:91
bool IsInitialBlockDownload()
Check whether we are doing an initial block download (synchronizing from disk or network) ...
std::unique_ptr< FascState > globalState
Global state.
Definition: validation.cpp:70
std::vector< FascTransaction > txs
Definition: validation.h:770
A mutable version of CTransaction.
Definition: transaction.h:390
std::vector< unsigned char > valtype
Definition: fascstate.h:17
unsigned int nIn
Definition: validation.h:549
CScript COINBASE_FLAGS
Constant stuff for coinbase transactions we create:
Definition: validation.cpp:113
FixedHash< 20 > h160
Definition: FixedHash.h:341
double GuessVerificationProgress(const ChainTxData &data, CBlockIndex *pindex)
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
std::vector< CTxOut > refundOutputs
Definition: validation.h:724
Permanence
Definition: State.h:82
int nScriptCheckThreads
Definition: validation.cpp:84
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:275
void Unserialize(Stream &s)
Definition: validation.h:423
std::unordered_map< uint256, CBlockIndex *, BlockHasher > BlockMap
Definition: validation.h:198
bool fPruneMode
True if we&#39;re running in -prune mode.
Definition: validation.cpp:90
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:201
bool fLogEvents
Definition: validation.cpp:88
int GetSpendHeight(const CCoinsViewCache &inputs)
Return the spend height, which is one more than the inputs.GetBestBlock().
int VersionBitsTipStateSinceHeight(const Consensus::Params &params, Consensus::DeploymentPos pos)
Get the block height at which the BIP9 deployment switched into the state for the block building on t...
const std::string strMessageMagic
Definition: validation.cpp:115
bool fCheckpointsEnabled
Definition: validation.cpp:94
bool FlushStateToDisk()
Flush all state, indexes and buffers to disk.
void Serialize(Stream &s) const
Definition: validation.h:418
bool GetBlockPublicKey(const CBlock &block, std::vector< unsigned char > &vchPubKey)
bool CheckTransaction(const CTransaction &tx, CValidationState &state, bool fCheckDuplicateInputs)
Transaction validation functions.
Definition: tx_verify.cpp:161
bool LoadGenesisBlock(const CChainParams &chainparams)
Ensures we have a genesis block in the block tree, possibly writing one to disk.
CBlockFileInfo * GetBlockFileInfo(size_t n)
Get block file info entry for one block file.
VersionBitsCache versionbitscache
uint64_t nLastBlockTx
Definition: miner.cpp:62
CBlockTreeDB * pblocktree
Global variable that points to the active block tree (protected by cs_main)
Definition: validation.cpp:253
uint8_t const * data
Definition: sha3.h:19
void writeVMlog(const std::vector< ResultExecute > &res, const CTransaction &tx=CTransaction(), const CBlock &block=CBlock())
unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Count ECDSA signature operations in pay-to-script-hash inputs.
Definition: tx_verify.cpp:123
bool CheckMinGasPrice(std::vector< EthTransactionParams > &etps, const uint64_t &minGasPrice)
void UnloadBlockIndex()
Unload database information.
bool fRecordLogOpcodes
Definition: validation.cpp:72
bool IsConfirmedInNPrevBlocks(const CDiskTxPos &txindex, const CBlockIndex *pindexFrom, int nMaxDepth, int &nActualDepth)
Check if the transaction is confirmed in N previous blocks.
bool LoadChainTip(const CChainParams &chainparams)
Update the chain tip based on database information.
bool ContextualCheckBlockHeader(const CBlockHeader &block, CValidationState &state, const Consensus::Params &consensusParams, const CBlockIndex *pindexPrev, int64_t nAdjustedTime)
Context-dependent validity checks.
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:35
const CBlock & block
Definition: validation.h:774
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune)
Actually unlink the specified files.
bool fCheckBlockIndex
Definition: validation.cpp:93
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced=nullptr, bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0, bool rawTx=false)
(try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions repla...
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
Definition: sync.h:91
std::vector< CTransaction > valueTransfers
Definition: validation.h:725
PrecomputedTransactionData * txdata
Definition: validation.h:553