Changeset View
Changeset View
Standalone View
Standalone View
src/validation.h
Show First 20 Lines • Show All 336 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool, | bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool, | ||||
TxValidationState &state, const CTransactionRef &tx, | TxValidationState &state, const CTransactionRef &tx, | ||||
bool bypass_limits, const Amount nAbsurdFee, | bool bypass_limits, const Amount nAbsurdFee, | ||||
bool test_accept = false) | bool test_accept = false) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
/** | /** | ||||
* Simple class for regulating resource usage during CheckInputs (and | * Simple class for regulating resource usage during CheckInputScripts (and | ||||
* CScriptCheck), atomic so as to be compatible with parallel validation. | * CScriptCheck), atomic so as to be compatible with parallel validation. | ||||
*/ | */ | ||||
class CheckInputsLimiter { | class CheckInputsLimiter { | ||||
protected: | protected: | ||||
std::atomic<int64_t> remaining; | std::atomic<int64_t> remaining; | ||||
public: | public: | ||||
explicit CheckInputsLimiter(int64_t limit) : remaining(limit) {} | explicit CheckInputsLimiter(int64_t limit) : remaining(limit) {} | ||||
Show All 26 Lines | static TxSigCheckLimiter getDisabled() { | ||||
txLimiter.remaining = 20000; | txLimiter.remaining = 20000; | ||||
return txLimiter; | return txLimiter; | ||||
} | } | ||||
}; | }; | ||||
class ConnectTrace; | class ConnectTrace; | ||||
/** | /** | ||||
* Check whether all inputs of this transaction are valid (no double spends, | * Check whether all of this transaction's input scripts succeed. | ||||
* scripts & sigs, amounts). This does not modify the UTXO set. | * | ||||
* This involves ECDSA signature checks so can be computationally intensive. | |||||
* This function should only be called after the cheap sanity checks in | |||||
* CheckTxInputs passed. | |||||
* | * | ||||
* If pvChecks is not nullptr, script checks are pushed onto it instead of being | * If pvChecks is not nullptr, script checks are pushed onto it instead of being | ||||
* performed inline. Any script checks which are not necessary (eg due to script | * performed inline. Any script checks which are not necessary (eg due to script | ||||
* execution cache hits) are, obviously, not pushed onto pvChecks/run. | * execution cache hits) are, obviously, not pushed onto pvChecks/run. | ||||
* | * | ||||
* Upon success nSigChecksOut will be filled in with either: | * Upon success nSigChecksOut will be filled in with either: | ||||
* - correct total for all inputs, or, | * - correct total for all inputs, or, | ||||
* - 0, in the case when checks were pushed onto pvChecks (i.e., a cache miss | * - 0, in the case when checks were pushed onto pvChecks (i.e., a cache miss | ||||
* with pvChecks non-null), in which case the total can be found by executing | * with pvChecks non-null), in which case the total can be found by executing | ||||
* pvChecks and adding the results. | * pvChecks and adding the results. | ||||
* | * | ||||
* Setting sigCacheStore/scriptCacheStore to false will remove elements from the | * Setting sigCacheStore/scriptCacheStore to false will remove elements from the | ||||
* corresponding cache which are matched. This is useful for checking blocks | * corresponding cache which are matched. This is useful for checking blocks | ||||
* where we will likely never need the cache entry again. | * where we will likely never need the cache entry again. | ||||
* | * | ||||
* pLimitSigChecks can be passed to limit the sigchecks count either in parallel | * pLimitSigChecks can be passed to limit the sigchecks count either in parallel | ||||
* or serial validation. With pvChecks null (serial validation), breaking the | * or serial validation. With pvChecks null (serial validation), breaking the | ||||
* pLimitSigChecks limit will abort evaluation early and return false. With | * pLimitSigChecks limit will abort evaluation early and return false. With | ||||
* pvChecks not-null (parallel validation): the cached nSigChecks may itself | * pvChecks not-null (parallel validation): the cached nSigChecks may itself | ||||
* break the limit in which case false is returned, OR, each entry in the | * break the limit in which case false is returned, OR, each entry in the | ||||
* returned pvChecks must be executed exactly once in order to probe the limit | * returned pvChecks must be executed exactly once in order to probe the limit | ||||
* accurately. | * accurately. | ||||
*/ | */ | ||||
bool CheckInputs(const CTransaction &tx, TxValidationState &state, | bool CheckInputScripts(const CTransaction &tx, TxValidationState &state, | ||||
const CCoinsViewCache &view, const uint32_t flags, | const CCoinsViewCache &view, const uint32_t flags, | ||||
bool sigCacheStore, bool scriptCacheStore, | bool sigCacheStore, bool scriptCacheStore, | ||||
const PrecomputedTransactionData &txdata, int &nSigChecksOut, | const PrecomputedTransactionData &txdata, | ||||
TxSigCheckLimiter &txLimitSigChecks, | int &nSigChecksOut, TxSigCheckLimiter &txLimitSigChecks, | ||||
CheckInputsLimiter *pBlockLimitSigChecks, | CheckInputsLimiter *pBlockLimitSigChecks, | ||||
std::vector<CScriptCheck> *pvChecks) | std::vector<CScriptCheck> *pvChecks) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
/** | /** | ||||
* Handy shortcut to full fledged CheckInputs call. | * Handy shortcut to full fledged CheckInputScripts call. | ||||
*/ | */ | ||||
static inline bool | static inline bool | ||||
CheckInputs(const CTransaction &tx, TxValidationState &state, | CheckInputScripts(const CTransaction &tx, TxValidationState &state, | ||||
const CCoinsViewCache &view, const uint32_t flags, | const CCoinsViewCache &view, const uint32_t flags, | ||||
bool sigCacheStore, bool scriptCacheStore, | bool sigCacheStore, bool scriptCacheStore, | ||||
const PrecomputedTransactionData &txdata, int &nSigChecksOut) | const PrecomputedTransactionData &txdata, int &nSigChecksOut) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | ||||
TxSigCheckLimiter nSigChecksTxLimiter; | TxSigCheckLimiter nSigChecksTxLimiter; | ||||
return CheckInputs(tx, state, view, flags, sigCacheStore, scriptCacheStore, | return CheckInputScripts(tx, state, view, flags, sigCacheStore, | ||||
txdata, nSigChecksOut, nSigChecksTxLimiter, nullptr, | scriptCacheStore, txdata, nSigChecksOut, | ||||
nullptr); | nSigChecksTxLimiter, nullptr, nullptr); | ||||
} | } | ||||
/** Get the BIP9 state for a given deployment at the current tip. */ | /** Get the BIP9 state for a given deployment at the current tip. */ | ||||
ThresholdState VersionBitsTipState(const Consensus::Params ¶ms, | ThresholdState VersionBitsTipState(const Consensus::Params ¶ms, | ||||
Consensus::DeploymentPos pos); | Consensus::DeploymentPos pos); | ||||
/** Get the BIP9 state for a given deployment at a given block. */ | /** Get the BIP9 state for a given deployment at a given block. */ | ||||
ThresholdState VersionBitsBlockState(const Consensus::Params ¶ms, | ThresholdState VersionBitsBlockState(const Consensus::Params ¶ms, | ||||
▲ Show 20 Lines • Show All 835 Lines • Show Last 20 Lines |