Raven Core  3.0.0
P2P Digital Currency
validation.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2017-2019 The Raven 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 RAVEN_VALIDATION_H
8 #define RAVEN_VALIDATION_H
9 
10 #if defined(HAVE_CONFIG_H)
11 #include "config/raven-config.h"
12 #endif
13 
14 #include "amount.h"
15 #include "coins.h"
16 #include "fs.h"
17 #include "protocol.h" // For CMessageHeader::MessageStartChars
18 #include "policy/feerate.h"
19 #include "script/script_error.h"
20 #include "sync.h"
21 #include "versionbits.h"
22 #include "spentindex.h"
23 #include "addressindex.h"
24 #include "timestampindex.h"
25 
26 #include <algorithm>
27 #include <exception>
28 #include <map>
29 #include <set>
30 #include <stdint.h>
31 #include <string>
32 #include <utility>
33 #include <vector>
34 
35 #include <atomic>
36 #include <assets/assets.h>
37 #include <assets/assetdb.h>
38 #include <assets/messages.h>
39 #include <assets/messagedb.h>
40 #include <assets/restricteddb.h>
41 
42 class CBlockIndex;
43 class CBlockTreeDB;
44 class CChainParams;
45 class CCoinsViewDB;
46 class CInv;
47 class CConnman;
48 class CScriptCheck;
50 class CTxMemPool;
51 class CValidationState;
52 class CTxUndo;
53 struct ChainTxData;
54 
55 class CAssetsDB;
56 class CAssets;
57 
59 struct LockPoints;
60 
62 static const bool DEFAULT_WHITELISTRELAY = true;
64 static const bool DEFAULT_WHITELISTFORCERELAY = true;
66 static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
67 static const unsigned int DEFAULT_MIN_RELAY_TX_FEE_V2 = 1000000;
69 static const CAmount DEFAULT_TRANSACTION_MAXFEE = 1000 * COIN;
71 static const CAmount HIGH_TX_FEE_PER_KB = 0.01 * COIN;
73 static const CAmount HIGH_MAX_TX_FEE = 100 * HIGH_TX_FEE_PER_KB;
75 static const unsigned int DEFAULT_ANCESTOR_LIMIT = 200;
77 static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 202;
79 static const unsigned int DEFAULT_DESCENDANT_LIMIT = 200;
81 static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 202;
83 static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
85 static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20000;
87 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
89 static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
91 static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
92 
94 static const int MAX_SCRIPTCHECK_THREADS = 16;
96 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
98 static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
100 static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
103 static const unsigned int MAX_HEADERS_RESULTS = 2000;
106 static const int MAX_CMPCTBLOCK_DEPTH = 5;
108 static const int MAX_BLOCKTXN_DEPTH = 10;
113 static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
115 static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
117 static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
119 static const unsigned int DATABASE_FLUSH_INTERVAL_SPEEDY = 60 * 10;
121 static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
123 static const unsigned int AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL = 24 * 60 * 60;
125 static const unsigned int AVG_ADDRESS_BROADCAST_INTERVAL = 30;
128 static const unsigned int INVENTORY_BROADCAST_INTERVAL = 5;
131 static const unsigned int INVENTORY_BROADCAST_MAX = 7 * INVENTORY_BROADCAST_INTERVAL;
133 static const unsigned int AVG_FEEFILTER_BROADCAST_INTERVAL = 10 * 60;
135 static const unsigned int MAX_FEEFILTER_CHANGE_DELAY = 5 * 60; // TODO Should we change this for raven, with 1 minutes block intervals?
137 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000;
139 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000;
140 
141 static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
143 static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60;
144 
146 static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
147 static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
148 static const bool DEFAULT_TXINDEX = false;
149 static const bool DEFAULT_ASSETINDEX = false;
150 static const bool DEFAULT_ADDRESSINDEX = false;
151 static const bool DEFAULT_TIMESTAMPINDEX = false;
152 static const bool DEFAULT_SPENTINDEX = false;
154 static const int64_t DEFAULT_DB_MAX_FILE_SIZE = 2;
155 
156 static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
158 static const bool DEFAULT_PERSIST_MEMPOOL = true;
160 static const bool DEFAULT_ENABLE_REPLACEMENT = false;
162 static const bool DEFAULT_FEEFILTER = true;
163 
165 static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;
166 
168 static const int MAX_UNCONNECTING_HEADERS = 10;
169 
170 static const bool DEFAULT_PEERBLOOMFILTERS = true;
171 
173 static const int DEFAULT_STOPATHEIGHT = 0;
174 
176 {
177  size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); }
178 };
179 
180 extern CScript COINBASE_FLAGS;
183 extern CTxMemPool mempool;
184 typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
185 extern BlockMap mapBlockIndex;
186 extern uint64_t nLastBlockTx;
187 extern uint64_t nLastBlockWeight;
188 extern const std::string strMessageMagic;
191 extern std::atomic_bool fImporting;
192 extern std::atomic_bool fReindex;
193 extern bool fMessaging;
194 extern int nScriptCheckThreads;
195 extern bool fTxIndex;
196 extern bool fAssetIndex;
197 extern bool fAddressIndex;
198 extern bool fSpentIndex;
199 extern bool fTimestampIndex;
200 extern bool fIsBareMultisigStd;
201 extern bool fRequireStandard;
202 extern bool fCheckBlockIndex;
203 extern bool fCheckpointsEnabled;
204 extern size_t nCoinCacheUsage;
206 extern CFeeRate minRelayTxFee;
208 extern CAmount maxTxFee;
211 
212 extern bool fUnitTest;
213 
214 
216 extern int64_t nMaxTipAge;
217 extern bool fEnableReplacement;
218 
220 extern uint256 hashAssumeValid;
221 
224 
227 
229 static const uint64_t nMinDiskSpace = 52428800;
230 
233 extern bool fHavePruned;
235 extern bool fPruneMode;
237 extern uint64_t nPruneTarget;
239 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
240 
241 static const signed int DEFAULT_CHECKBLOCKS = 6;
242 static const unsigned int DEFAULT_CHECKLEVEL = 3;
243 
244 // Require that user allocate at least 550MB for block & undo files (blk???.dat and rev???.dat)
245 // At 1MB per block, 288 blocks = 288MB.
246 // Add 15% for Undo data = 331MB
247 // Add 20% for Orphan block rate = 397MB
248 // We want the low water mark after pruning to be at least 397 MB and since we prune in
249 // full block file chunks, we need the high water mark which triggers the prune to be
250 // one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB
251 // Setting the target to > than 550MB will make it likely we can respect the target.
252 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
253 
273 bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock);
274 
286 bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, CValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex=nullptr, CBlockHeader *first_invalid=nullptr);
287 
289 bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
291 FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
293 fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix);
295 bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp = nullptr);
297 bool LoadGenesisBlock(const CChainParams& chainparams);
300 bool LoadBlockIndex(const CChainParams& chainparams);
302 bool LoadChainTip(const CChainParams& chainparams);
304 void UnloadBlockIndex();
306 void ThreadScriptCheck();
309 bool IsInitialSyncSpeedUp();
311 bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false);
313 bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
314 CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
315 
317 double GuessVerificationProgress(const ChainTxData& data, CBlockIndex* pindex);
318 
320 uint64_t CalculateCurrentUsage();
321 
325 void PruneOneBlockFile(const int fileNumber);
326 
330 void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune);
331 
335 void FlushStateToDisk();
337 void PruneAndFlush();
339 void PruneBlockFilesManual(int nManualPruneHeight);
340 
343 bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx,
344  bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced,
345  bool bypass_limits, const CAmount nAbsurdFee);
346 
348 std::string FormatStateMessage(const CValidationState &state);
349 
352 
355 
358 
359 
361 void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
362 
363 void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo& txundo, int nHeight, uint256 blockHash, CAssetsCache* assetCache = nullptr, std::pair<std::string, CBlockAssetUndo>* undoAssetData = nullptr);
364 
374 bool CheckFinalTx(const CTransaction &tx, int flags = -1);
375 
379 bool TestLockPointValidity(const LockPoints* lp);
380 
392 bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false);
393 
399 {
400 private:
403  unsigned int nIn;
404  unsigned int nFlags;
408 
409 public:
410  CScriptCheck(): ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
411  CScriptCheck(const CTxOut& outIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
412  m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
413 
414  bool operator()();
415 
416  void swap(CScriptCheck &check) {
417  std::swap(ptxTo, check.ptxTo);
418  std::swap(m_tx_out, check.m_tx_out);
419  std::swap(nIn, check.nIn);
420  std::swap(nFlags, check.nFlags);
421  std::swap(cacheStore, check.cacheStore);
422  std::swap(error, check.error);
423  std::swap(txdata, check.txdata);
424  }
425 
426  ScriptError GetScriptError() const { return error; }
427 };
428 
431 
432 bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, const bool fActiveOnly, std::vector<std::pair<uint256, unsigned int> > &hashes);
434 bool HashOnchainActive(const uint256 &hash);
435 bool GetAddressIndex(uint160 addressHash, int type, std::string assetName,
436  std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
437  int start = 0, int end = 0);
438 bool GetAddressIndex(uint160 addressHash, int type,
439  std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
440  int start = 0, int end = 0);
441 bool GetAddressUnspent(uint160 addressHash, int type, std::string assetName,
442  std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs);
443 bool GetAddressUnspent(uint160 addressHash, int type,
444  std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs);
445 
447 bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams);
448 bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams);
449 
453 bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
454 
456 bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
457 
459 bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
460 
462 bool RewindBlockIndex(const CChainParams& params);
463 
465 void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
466 
468 std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
469 
471 class CVerifyDB {
472 public:
473  CVerifyDB();
474  ~CVerifyDB();
475  bool VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth);
476 };
477 
479 bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
480 
482 CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator);
483 
485 bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex *pindex);
486 
488 bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex);
489 
491 bool ResetBlockFailureFlags(CBlockIndex *pindex);
492 
494 extern CChain chainActive;
495 
497 extern CCoinsViewDB *pcoinsdbview;
498 
500 extern CCoinsViewCache *pcoinsTip;
501 
503 extern CBlockTreeDB *pblocktree;
504 
508 extern CAssetsDB *passetsdb;
509 
511 extern CAssetsCache *passets;
512 
515 
518 
521 
524 
526 extern CMessageDB *pmessagedb;
527 
530 
533 
536 
538 extern CLRUCache<std::string, int8_t> *passetsQualifierCache; // hash(address,qualifier_name) ->int8_t
539 
541 extern CLRUCache<std::string, int8_t> *passetsRestrictionCache; // hash(address,qualifier_name) ->int8_t
542 
545 
553 int GetSpendHeight(const CCoinsViewCache& inputs);
554 
556 
560 int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params);
561 
566 static const unsigned int REJECT_INTERNAL = 0x100;
568 static const unsigned int REJECT_HIGHFEE = 0x100;
569 
572 
574 bool DumpMempool();
575 
577 bool LoadMempool();
578 
580 bool AreAssetsDeployed();
581 
582 bool AreMessagingDeployed();
583 
585 
586 bool IsDGWActive(unsigned int nBlockNumber);
587 bool IsMessagingActive(unsigned int nBlockNumber);
588 bool IsRestrictedActive(unsigned int nBlockNumber);
589 
593 #endif // RAVEN_VALIDATION_H
CCoinsViewDB * pcoinsdbview
Global variable that points to the coins database (protected by cs_main)
Definition: validation.cpp:222
bool fTimestampIndex
Definition: validation.cpp:86
CTxMemPool mempool
CMessageDB * pmessagedb
Global variable that points to the messages database (protected by cs_main)
Definition: validation.cpp:232
void FlushStateToDisk()
Flush all state, indexes and buffers to disk.
size_t nCoinCacheUsage
Definition: validation.cpp:94
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:96
boost::condition_variable CConditionVariable
Just a typedef for boost::condition_variable, can be wrapped later if desired.
Definition: sync.h:104
bool IsMessagingActive(unsigned int nBlockNumber)
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:132
void PruneOneBlockFile(const int fileNumber)
Mark one block file as pruned.
CConditionVariable cvBlockChange
Definition: validation.cpp:78
bool fTxIndex
Definition: validation.cpp:83
int flags
Definition: raven-tx.cpp:500
void swap(CScriptCheck &check)
Definition: validation.h:416
Definition: assets.h:72
Definition: block.h:73
CMessageChannelDB * pmessagechanneldb
Global variable that points to the message channel database (protected by cs_main) ...
Definition: validation.cpp:233
CRestrictedDB * prestricteddb
Global variable that points to the active restricted asset database (protected by cs_main) ...
Definition: validation.cpp:239
An in-memory indexed chain of blocks.
Definition: chain.h:437
bool fAddressIndex
Definition: validation.cpp:85
uint64_t CalculateCurrentUsage()
Calculate the amount of disk space the block & undo files currently use.
unsigned int nFlags
Definition: validation.h:404
void PruneBlockFilesManual(int nManualPruneHeight)
Prune block files up to a given height.
inv message data
Definition: protocol.h:397
CBlockIndex * pindexBestHeader
Best header we&#39;ve seen so far (used for getheaders queries&#39; starting points).
Definition: validation.cpp:76
CLRUCache< std::string, int > * pMessagesSeenAddressCache
Global variable that points to the address seen LRU Cache (protected by cs_main)
Definition: validation.cpp:231
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.
const char * prefix
Definition: rest.cpp:568
bool ResetBlockFailureFlags(CBlockIndex *pindex)
Remove invalidity status from a block and its descendants.
CBlockPolicyEstimator feeEstimator
Definition: validation.cpp:109
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:204
bool PreciousBlock(CValidationState &state, const CChainParams &params, CBlockIndex *pindex)
Mark a block as precious and reorganize.
sph_u32 high
Definition: keccak.c:370
CAssetsCache * GetCurrentAssetCache()
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: validation.cpp:223
BlockMap mapBlockIndex
Definition: validation.cpp:74
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 fSpentIndex
Definition: validation.cpp:87
CChainParams defines various tweakable parameters of a given instance of the Raven system...
Definition: chainparams.h:48
ScriptError error
Definition: validation.h:406
CLRUCache< std::string, int8_t > * passetsGlobalRestrictionCache
Global variable that points to the global asset restriction LRU Cache (protected by cs_main) ...
Definition: validation.cpp:238
ThresholdState
Definition: versionbits.h:27
CLRUCache< std::string, int8_t > * passetsQualifierCache
Global variable that points to the asset address qualifier LRU Cache (protected by cs_main) ...
Definition: validation.cpp:236
bool LoadMempool()
Load the mempool from disk.
bool cacheStore
Definition: validation.h:405
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:436
bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, const bool fActiveOnly, std::vector< std::pair< uint256, unsigned int > > &hashes)
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.
CTxOut m_tx_out
Definition: validation.h:401
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)
Transaction validation functions.
Definition: validation.cpp:255
bool fEnableReplacement
Definition: validation.cpp:97
CLRUCache< std::string, CDatabasedAssetData > * passetsCache
Global variable that point to the assets metadata LRU Cache (protected by cs_main) ...
Definition: validation.cpp:228
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData *txdataIn)
Definition: validation.h:411
CCriticalSection cs_main
Global state.
Definition: validation.cpp:72
bool IsDGWActive(unsigned int nBlockNumber)
bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
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...
bool InvalidateBlock(CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex)
Mark a block as invalid.
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
void UpdateUncommittedBlockStructures(CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams)
Update uncommitted block structures (currently: only the witness nonce).
bool GetAddressUnspent(uint160 addressHash, int type, std::string assetName, std::vector< std::pair< CAddressUnspentKey, CAddressUnspentValue > > &unspentOutputs)
bool GetAddressIndex(uint160 addressHash, int type, std::string assetName, std::vector< std::pair< CAddressIndexKey, CAmount > > &addressIndex, int start=0, int end=0)
Access to the block database (blocks/index/)
Definition: txdb.h:113
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced, bool bypass_limits, const CAmount nAbsurdFee)
(try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions repla...
Abstract view on the open txout dataset.
Definition: coins.h:152
DeploymentPos
Definition: params.h:16
bool fHavePruned
Pruning-related variables and constants.
Definition: validation.cpp:88
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:139
bool IsInitialSyncSpeedUp()
fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix)
Translation to a filesystem path.
bool AreMessagingDeployed()
CFeeRate minRelayTxFeeV2
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
Definition: validation.cpp:107
bool AreAssetsDeployed()
RVN START.
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:471
bool LoadBlockIndex(const CChainParams &chainparams)
Load the block tree and coins database from disk, initializing state if we&#39;re running with -reindex...
bool IsRestrictedActive(unsigned int nBlockNumber)
arith_uint256 nMinimumChainWork
Minimum work we will assume exists on some valid chain.
Definition: validation.cpp:102
bool TestLockPointValidity(const LockPoints *lp)
Test whether the LockPoints height and time are still valid on the current chain. ...
Definition: validation.cpp:287
Definition: net.h:120
An output of a transaction.
Definition: transaction.h:137
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
Parameters that influence chain consensus.
Definition: params.h:47
std::string FormatStateMessage(const CValidationState &state)
Convert CValidationState to a human-readable message for logging.
Definition: validation.cpp:393
CLRUCache< std::string, int8_t > * passetsRestrictionCache
Global variable that points to the asset address restriction LRU Cache (protected by cs_main) ...
Definition: validation.cpp:237
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)
bool HashOnchainActive(const uint256 &hash)
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Determine what nVersion a new block should use.
size_t operator()(const uint256 &hash) const
Definition: validation.h:177
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.
uint64_t nPruneTarget
Number of MiB of block files that we&#39;re trying to stay below.
Definition: validation.cpp:95
Closure representing one script verification Note that this stores references to the spending transac...
Definition: validation.h:398
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:305
bool fAssetIndex
Definition: validation.cpp:84
CAssetsDB * passetsdb
RVN START.
Definition: validation.cpp:226
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
Definition: validation.cpp:104
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:75
std::atomic_bool fReindex
bool RewindBlockIndex(const CChainParams &params)
When there are blocks in the active chain with missing data, rewind the chainstate and remove them fr...
CAssetsCache * passets
Global variable that point to the active assets (protected by cs_main)
Definition: validation.cpp:227
bool fMessaging
Definition: validation.cpp:82
RVN END.
Definition: validation.h:30
256-bit opaque blob.
Definition: uint256.h:123
const CTransaction * ptxTo
Definition: validation.h:402
uint64_t nLastBlockWeight
Definition: miner.cpp:54
CLRUCache< std::string, CNullAssetTxVerifierString > * passetsVerifierCache
Global variable that points to the asset verifier LRU Cache (protected by cs_main) ...
Definition: validation.cpp:235
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:416
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:55
CWaitableCriticalSection csBestBlock
Definition: validation.cpp:77
bool fRequireStandard
Definition: validation.cpp:91
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:172
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:396
RVN START.
Definition: undo.h:72
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:71
CAmount maxTxFee
Absolute maximum transaction fee (in satoshis) used by wallet and mempool (rejects high fee in sendra...
Definition: validation.cpp:105
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:101
bool CheckDiskSpace(uint64_t nAdditionalBytes=0)
Check whether enough disk space is available for an incoming block.
sph_u32 low
Definition: keccak.c:370
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...
void PruneAndFlush()
Prune block files and flush state to disk.
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:20
CBlockIndex * InsertBlockIndex(uint256 hash)
Create a new block index entry for a given block hash.
160-bit opaque blob.
Definition: uint256.h:112
void ThreadScriptCheck()
Run an instance of the script checking thread.
bool fIsBareMultisigStd
Definition: validation.cpp:90
bool error(const char *fmt, const Args &... args)
Definition: util.h:168
bool IsInitialBlockDownload()
Check whether we are doing an initial block download (synchronizing from disk or network) ...
CLRUCache< std::string, int > * pMessageSubscribedChannelsCache
Global variable that points to the subscribed channel LRU Cache (protected by cs_main) ...
Definition: validation.cpp:230
bool fUnitTest
Definition: validation.cpp:99
unsigned int nIn
Definition: validation.h:403
CScript COINBASE_FLAGS
Constant stuff for coinbase transactions we create:
Definition: validation.cpp:115
double GuessVerificationProgress(const ChainTxData &data, CBlockIndex *pindex)
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
int nScriptCheckThreads
Definition: validation.cpp:79
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:270
std::unordered_map< uint256, CBlockIndex *, BlockHasher > BlockMap
Definition: validation.h:184
bool fPruneMode
True if we&#39;re running in -prune mode.
Definition: validation.cpp:89
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:208
int GetSpendHeight(const CCoinsViewCache &inputs)
RVN END.
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...
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:140
const std::string strMessageMagic
Definition: validation.cpp:117
bool fCheckpointsEnabled
Definition: validation.cpp:93
CLRUCache< std::string, CMessage > * pMessagesCache
Global variable that points to the subscribed channel LRU Cache (protected by cs_main) ...
Definition: validation.cpp:229
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
ScriptError GetScriptError() const
Definition: validation.h:426
bool DumpMempool()
Dump the mempool to disk.
uint64_t nLastBlockTx
Definition: miner.cpp:53
CBlockTreeDB * pblocktree
Global variable that points to the active block tree (protected by cs_main)
Definition: validation.cpp:224
void UnloadBlockIndex()
Unload database information.
bool AreRestrictedAssetsDeployed()
Access to the block database (blocks/index/)
Definition: assetdb.h:60
bool LoadChainTip(const CChainParams &chainparams)
Update the chain tip based on database information.
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:21
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune)
Actually unlink the specified files.
bool fCheckBlockIndex
Definition: validation.cpp:92
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
Definition: sync.h:92
PrecomputedTransactionData * txdata
Definition: validation.h:407