11 #ifndef PIVX_VALIDATION_H
12 #define PIVX_VALIDATION_H
14 #if defined(HAVE_CONFIG_H)
56 static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25;
58 static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
60 static const int DEFAULT_BANSCORE_THRESHOLD = 100;
62 static const bool DEFAULT_PERSIST_MEMPOOL =
true;
64 static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
66 static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
68 static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 72;
70 static const bool DEFAULT_TXINDEX =
true;
71 static const bool DEFAULT_CHECKPOINTS_ENABLED =
true;
73 static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
74 static const unsigned int MAX_ZEROCOIN_TX_SIZE = 150000;
76 static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20000;
78 static const signed int DEFAULT_CHECKBLOCKS = 6;
79 static const unsigned int DEFAULT_CHECKLEVEL = 3;
81 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000;
83 static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000;
85 static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000;
87 static const int MAX_SCRIPTCHECK_THREADS = 16;
89 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
91 static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
93 static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
96 static const unsigned int MAX_HEADERS_RESULTS = 2000;
101 static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
103 static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
105 static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
107 static constexpr std::chrono::hours AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL{24};
109 static constexpr std::chrono::seconds AVG_ADDRESS_BROADCAST_INTERVAL{30};
111 static const unsigned int DEFAULT_SHIELDEDTXFEE_K = 100;
113 static const bool DEFAULT_PEERBLOOMFILTERS =
true;
115 static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
117 static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60;
126 typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher>
BlockMap;
127 typedef std::unordered_multimap<uint256, CBlockIndex*, BlockHasher>
PrevBlockMap;
221 bool* pfMissingInputs,
bool fOverrideMempoolLimit =
false,
226 bool* pfMissingInputs, int64_t nAcceptTime,
bool fOverrideMempoolLimit =
false,
292 precomTxData(cachedHashesIn) {}
298 std::swap(ptxTo, check.
ptxTo);
299 std::swap(m_tx_out, check.
m_tx_out);
300 std::swap(nIn, check.
nIn);
301 std::swap(nFlags, check.
nFlags);
339 bool VerifyDB(
CCoinsView* coinsview,
int nCheckLevel,
int nCheckDepth);
368 extern std::unique_ptr<CCoinsViewCache>
pcoinsTip;
371 extern std::unique_ptr<CBlockTreeDB>
pblocktree;
374 extern std::unique_ptr<CZerocoinDB>
zerocoinDB;
380 extern std::unique_ptr<CSporkDB>
pSporkDB;
398 static const unsigned int REJECT_INTERNAL = 0x100;
400 static const unsigned int REJECT_HIGHFEE = 0x100;
402 static const unsigned int REJECT_ALREADY_KNOWN = 0x101;
404 static const unsigned int REJECT_CONFLICT = 0x102;
int64_t CAmount
Amount in PIV (Can be negative)
The block chain is a tree shaped structure starting with the genesis block at the root,...
Access to the block database (blocks/index/)
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
An in-memory indexed chain of blocks.
CChainParams defines various tweakable parameters of a given instance of the PIVX system.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
CCoinsView backed by the LevelDB coin database (chainstate/)
Abstract view on the open txout dataset.
Fee rate in PIV per kilobyte: CAmount / kB.
Information about a peer.
Closure representing one script verification Note that this stores references to the spending transac...
ScriptError GetScriptError() const
void swap(CScriptCheck &check)
PrecomputedTransactionData * precomTxData
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData *cachedHashesIn)
const CTransaction * ptxTo
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
An output of a transaction.
Capture information about block/transaction validation.
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Zerocoin database (zerocoin/)
uint64_t GetCheapHash() const
A cheap hash function that just returns 64 bits from the result, it can be used when the contents are...
enum ScriptError_t ScriptError
@ SCRIPT_ERR_UNKNOWN_ERROR
size_t operator()(const uint256 &hash) const
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
#define AssertLockHeld(cs)
bool error(const char *fmt, const Args &... args)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
std::shared_ptr< const CTransaction > CTransactionRef
bool AcceptToMemoryPoolWithTime(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, int64_t nAcceptTime, bool fOverrideMempoolLimit=false, bool fRejectInsaneFee=false, bool ignoreFees=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
(try to) add transaction to memory pool with a specified acceptance time
double ConvertBitsToDouble(unsigned int nBits)
bool TestBlockValidity(CValidationState &state, const CBlock &block, CBlockIndex *pindexPrev, bool fCheckPOW=true, bool fCheckMerkleRoot=true, bool fCheckBlockSig=true) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Check a block is completely valid from start to finish (only works on top of our current best block,...
void FlushStateToDisk()
Flush all state, indexes and buffers to disk.
bool LoadGenesisBlock()
Ensures we have a genesis block in the block tree, possibly writing one to disk.
FILE * OpenUndoFile(const FlatFilePos &pos, bool fReadOnly=false)
Open an undo file (rev?????.dat)
int ActiveProtocol()
See whether the protocol update is enforced for connected nodes.
std::unique_ptr< CBlockTreeDB > pblocktree
Global variable that points to the active block tree (protected by cs_main)
std::unique_ptr< CZerocoinDB > zerocoinDB
Global variable that points to the zerocoin database (protected by cs_main)
std::condition_variable g_best_block_cv
CAmount GetShieldedTxMinFee(const CTransaction &tx)
Return the minimum fee for a shielded tx.
std::unique_ptr< CSporkDB > pSporkDB
Global variable that points to the spork database (protected by cs_main)
bool LoadChainTip(const CChainParams &chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Update the chain tip based on database information.
bool LoadBlockIndex(std::string &strError) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Load the block tree and coins database from disk, initializing state if we're running with -reindex.
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
bool DumpMempool(const CTxMemPool &pool)
Dump the mempool to disk.
bool WriteBlockToDisk(const CBlock &block, FlatFilePos &pos)
Functions for disk access for blocks.
bool CheckBlock(const CBlock &block, CValidationState &state, bool fCheckPOW=true, bool fCheckMerkleRoot=true, bool fCheckSig=true) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Functions for validating blocks and updating the block tree.
bool LoadMempool(CTxMemPool &pool)
Load the mempool from disk.
CFeeRate minRelayTxFee
Fees smaller than this (in upiv) are considered zero fee (for relaying, mining and transaction creati...
bool CheckWork(const CBlock &block, const CBlockIndex *const pindexPrev)
CScript COINBASE_FLAGS
Constant stuff for coinbase transactions we create:
bool IsInitialBlockDownload()
Check whether we are doing an initial block download (synchronizing from disk or network)
bool ProcessNewBlock(const std::shared_ptr< const CBlock > &pblock, const FlatFilePos *dbp)
Process an incoming block.
std::unordered_map< uint256, CBlockIndex *, BlockHasher > BlockMap
std::unique_ptr< CCoinsViewCache > pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
int64_t g_best_block_time
CBlockFileInfo * GetBlockFileInfo(size_t n)
Get block file info entry for one block file.
int64_t GetMasternodePayment(int nHeight)
CAmount GetBlockValue(int nHeight)
std::atomic< bool > fImporting
FILE * OpenBlockFile(const FlatFilePos &pos, bool fReadOnly=false)
Open a block file (blk?????.dat)
bool ReconsiderBlock(CValidationState &state, CBlockIndex *pindex)
Remove invalidity status from a block and its descendants.
std::map< uint256, int64_t > mapRejectedBlocks
bool AcceptBlockHeader(const CBlock &block, CValidationState &state, CBlockIndex **ppindex=nullptr, CBlockIndex *pindexPrev=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
bool GetTransaction(const uint256 &hash, CTransactionRef &tx, uint256 &hashBlock, bool fAllowSlow=false, CBlockIndex *blockIndex=nullptr)
Retrieve a transaction (from memory pool, or from disk, if possible)
void ThreadScriptCheck()
Run an instance of the script checking thread.
CBlockIndex * FindForkInGlobalIndex(const CChain &chain, const CBlockLocator &locator) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Find the last common block between the parameter chain and a locator.
fs::path GetBlockPosFilename(const FlatFilePos &pos)
Translation to a filesystem path.
std::unordered_multimap< uint256, CBlockIndex *, BlockHasher > PrevBlockMap
bool fLargeWorkInvalidChainFound
bool GetOutput(const uint256 &hash, unsigned int index, CValidationState &state, CTxOut &out)
Retrieve an output (from memory pool, or from disk, if possible)
RecursiveMutex cs_main
Global state.
bool ActivateBestChain(CValidationState &state, 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.
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, int nHeight, bool fSkipInvalid=false)
Apply the effects of this transaction on the UTXO set represented by view.
bool InvalidateBlock(CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark a block as invalid.
std::unique_ptr< CCoinsViewDB > pcoinsdbview
Global variable that points to the coins database (protected by cs_main)
void UnloadBlockIndex()
Unload database information.
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos)
CAmount GetMinRelayFee(const CTransaction &tx, const CTxMemPool &pool, unsigned int nBytes)
CBlockIndex * pindexBestHeader
Best header we've seen so far (used for getheaders queries' starting points).
bool ReplayBlocks(const CChainParams ¶ms, CCoinsView *view)
Replay blocks that aren't fully applied to the database.
PrevBlockMap mapPrevBlockIndex
CBlockIndex * GetChainTip()
Return a reliable pointer (in mapBlockIndex) to the chain's tip index.
bool CheckFinalTx(const CTransactionRef &tx, int flags=-1)
Check if transaction will be final in the next block to be created.
std::atomic< bool > fReindex
int GetSpendHeight(const CCoinsViewCache &inputs)
Return the spend height, which is one more than the inputs.GetBestBlock().
bool ContextualCheckBlockHeader(const CBlockHeader &block, CValidationState &state, CBlockIndex *pindexPrev) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Context-dependent validity checks.
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, bool fOverrideMempoolLimit=false, bool fRejectInsaneFee=false, bool ignoreFees=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
(try to) add transaction to memory pool
bool ContextualCheckBlock(const CBlock &block, CValidationState &state, CBlockIndex *pindexPrev)
std::unique_ptr< AccumulatorCache > accumulatorCache
In-memory cache for the zerocoin accumulators.
bool CheckInputs(const CTransaction &tx, CValidationState &state, const CCoinsViewCache &view, bool fScriptChecks, unsigned int flags, bool cacheStore, PrecomputedTransactionData &precomTxData, std::vector< CScriptCheck > *pvChecks=nullptr)
Check transaction inputs, and make sure any pay-to-script-hash transactions are evaluating IsStandard...
CBlockIndex * InsertBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Create a new block index entry for a given block hash.
bool LoadExternalBlockFile(FILE *fileIn, FlatFilePos *dbp=nullptr)
Import blocks from an external file.