7 #ifndef RAVEN_VALIDATION_H 8 #define RAVEN_VALIDATION_H 10 #if defined(HAVE_CONFIG_H) 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;
89 static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000;
91 static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000;
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;
137 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000;
139 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000;
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;
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;
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;
165 static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;
168 static const int MAX_UNCONNECTING_HEADERS = 10;
170 static const bool DEFAULT_PEERBLOOMFILTERS =
true;
173 static const int DEFAULT_STOPATHEIGHT = 0;
184 typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher>
BlockMap;
229 static const uint64_t nMinDiskSpace = 52428800;
239 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
241 static const signed int DEFAULT_CHECKBLOCKS = 6;
242 static const unsigned int DEFAULT_CHECKLEVEL = 3;
252 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
273 bool ProcessNewBlock(
const CChainParams& chainparams,
const std::shared_ptr<const CBlock> pblock,
bool fForceProcessing,
bool* fNewBlock);
344 bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced,
345 bool bypass_limits,
const CAmount nAbsurdFee);
412 m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(
SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
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);
422 std::swap(error, check.
error);
423 std::swap(txdata, check.
txdata);
432 bool GetTimestampIndex(
const unsigned int &
high,
const unsigned int &
low,
const bool fActiveOnly, std::vector<std::pair<uint256, unsigned int> > &hashes);
436 std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
437 int start = 0,
int end = 0);
439 std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
440 int start = 0,
int end = 0);
442 std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs);
444 std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs);
566 static const unsigned int REJECT_INTERNAL = 0x100;
568 static const unsigned int REJECT_HIGHFEE = 0x100;
593 #endif // RAVEN_VALIDATION_H CCoinsViewDB * pcoinsdbview
Global variable that points to the coins database (protected by cs_main)
CMessageDB * pmessagedb
Global variable that points to the messages database (protected by cs_main)
void FlushStateToDisk()
Flush all state, indexes and buffers to disk.
int64_t nMaxTipAge
If the tip is older than this (in seconds), the node is considered to be in initial block download...
boost::condition_variable CConditionVariable
Just a typedef for boost::condition_variable, can be wrapped later if desired.
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't have the sam...
void PruneOneBlockFile(const int fileNumber)
Mark one block file as pruned.
CConditionVariable cvBlockChange
void swap(CScriptCheck &check)
CMessageChannelDB * pmessagechanneldb
Global variable that points to the message channel database (protected by cs_main) ...
CRestrictedDB * prestricteddb
Global variable that points to the active restricted asset database (protected by cs_main) ...
An in-memory indexed chain of blocks.
uint64_t CalculateCurrentUsage()
Calculate the amount of disk space the block & undo files currently use.
void PruneBlockFilesManual(int nManualPruneHeight)
Prune block files up to a given height.
CBlockIndex * pindexBestHeader
Best header we've seen so far (used for getheaders queries' starting points).
CLRUCache< std::string, int > * pMessagesSeenAddressCache
Global variable that points to the address seen LRU Cache (protected by cs_main)
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 ResetBlockFailureFlags(CBlockIndex *pindex)
Remove invalidity status from a block and its descendants.
CBlockPolicyEstimator feeEstimator
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.
bool PreciousBlock(CValidationState &state, const CChainParams ¶ms, CBlockIndex *pindex)
Mark a block as precious and reorganize.
CAssetsCache * GetCurrentAssetCache()
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
bool ProcessNewBlockHeaders(const std::vector< CBlockHeader > &block, CValidationState &state, const CChainParams &chainparams, const CBlockIndex **ppindex=nullptr, CBlockHeader *first_invalid=nullptr)
Process incoming block headers.
CChainParams defines various tweakable parameters of a given instance of the Raven system...
CLRUCache< std::string, int8_t > * passetsGlobalRestrictionCache
Global variable that points to the global asset restriction LRU Cache (protected by cs_main) ...
CLRUCache< std::string, int8_t > * passetsQualifierCache
Global variable that points to the asset address qualifier LRU Cache (protected by cs_main) ...
bool LoadMempool()
Load the mempool from disk.
std::shared_ptr< const CTransaction > CTransactionRef
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.
BIP9Stats VersionBitsTipStatistics(const Consensus::Params ¶ms, 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.
CLRUCache< std::string, CDatabasedAssetData > * passetsCache
Global variable that point to the assets metadata LRU Cache (protected by cs_main) ...
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData *txdataIn)
CCriticalSection cs_main
Global state.
bool IsDGWActive(unsigned int nBlockNumber)
bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
int64_t CAmount
Amount in corbies (Can be negative)
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/)
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.
bool fHavePruned
Pruning-related variables and constants.
void InitScriptExecutionCache()
Initializes the script-execution cache.
We want to be able to estimate feerates that are needed on tx's to be included in a certain number of...
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) ...
bool AreAssetsDeployed()
RVN START.
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
bool LoadBlockIndex(const CChainParams &chainparams)
Load the block tree and coins database from disk, initializing state if we're running with -reindex...
bool IsRestrictedActive(unsigned int nBlockNumber)
arith_uint256 nMinimumChainWork
Minimum work we will assume exists on some valid chain.
bool TestLockPointValidity(const LockPoints *lp)
Test whether the LockPoints height and time are still valid on the current chain. ...
An output of a transaction.
ThresholdState VersionBitsTipState(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the BIP9 state for a given deployment at the current tip.
std::atomic_bool fImporting
Parameters that influence chain consensus.
std::string FormatStateMessage(const CValidationState &state)
Convert CValidationState to a human-readable message for logging.
CLRUCache< std::string, int8_t > * passetsRestrictionCache
Global variable that points to the asset address restriction LRU Cache (protected by cs_main) ...
bool ReplayBlocks(const CChainParams ¶ms, CCoinsView *view)
Replay blocks that aren'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 ¶ms)
Determine what nVersion a new block should use.
size_t operator()(const uint256 &hash) const
bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params ¶ms, 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're trying to stay below.
Closure representing one script verification Note that this stores references to the spending transac...
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.
CAssetsDB * passetsdb
RVN START.
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
std::atomic_bool fReindex
bool RewindBlockIndex(const CChainParams ¶ms)
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)
const CTransaction * ptxTo
uint64_t nLastBlockWeight
CLRUCache< std::string, CNullAssetTxVerifierString > * passetsVerifierCache
Global variable that points to the asset verifier LRU Cache (protected by cs_main) ...
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
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...
CWaitableCriticalSection csBestBlock
bool IsWitnessEnabled(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms)
Check whether witness commitments are required for block.
The block chain is a tree shaped structure starting with the genesis block at the root...
Serialized script, used inside transaction inputs and outputs.
CCoinsView backed by the coin database (chainstate/)
CAmount maxTxFee
Absolute maximum transaction fee (in satoshis) used by wallet and mempool (rejects high fee in sendra...
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.
bool CheckDiskSpace(uint64_t nAdditionalBytes=0)
Check whether enough disk space is available for an incoming block.
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't call for mined blocks...
void PruneAndFlush()
Prune block files and flush state to disk.
Fee rate in satoshis per kilobyte: CAmount / kB.
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.
bool error(const char *fmt, const Args &... args)
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) ...
CScript COINBASE_FLAGS
Constant stuff for coinbase transactions we create:
double GuessVerificationProgress(const ChainTxData &data, CBlockIndex *pindex)
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
The basic transaction that is broadcasted on the network and contained in blocks. ...
std::unordered_map< uint256, CBlockIndex *, BlockHasher > BlockMap
bool fPruneMode
True if we're running in -prune mode.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
int GetSpendHeight(const CCoinsViewCache &inputs)
RVN END.
int VersionBitsTipStateSinceHeight(const Consensus::Params ¶ms, 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...
const std::string strMessageMagic
CLRUCache< std::string, CMessage > * pMessagesCache
Global variable that points to the subscribed channel LRU Cache (protected by cs_main) ...
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
bool DumpMempool()
Dump the mempool to disk.
CBlockTreeDB * pblocktree
Global variable that points to the active block tree (protected by cs_main)
void UnloadBlockIndex()
Unload database information.
bool AreRestrictedAssetsDeployed()
Access to the block database (blocks/index/)
bool LoadChainTip(const CChainParams &chainparams)
Update the chain tip based on database information.
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune)
Actually unlink the specified files.
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
PrecomputedTransactionData * txdata