Changeset View
Changeset View
Standalone View
Standalone View
src/validation.h
Show First 20 Lines • Show All 516 Lines • ▼ Show 20 Lines | |||||
* See consensus/consensus.h for flag definitions. | * See consensus/consensus.h for flag definitions. | ||||
*/ | */ | ||||
bool CheckSequenceLocks(const CTxMemPool &pool, const CTransaction &tx, | bool CheckSequenceLocks(const CTxMemPool &pool, const CTransaction &tx, | ||||
int flags, LockPoints *lp = nullptr, | int flags, LockPoints *lp = nullptr, | ||||
bool useExistingLockPoints = false) | bool useExistingLockPoints = false) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
/** | /** | ||||
* Closure representing one script verification. | * Counts the consumption of transaction-level script resources during calls to | ||||
* Note that this stores references to the spending transaction. | * CScriptChecks. Has two responsibilities: | ||||
* - Obtain an accurate count of sigChecks for valid transactions. | |||||
* - Also, if the metrics gets too high (over a hardcoded limit) then allow this | |||||
* to be detected, thereby enforcing a hardcoded per-tx consensus rule on | |||||
* accumulated metrics. | |||||
* | |||||
* Currently, just tracks sigchecks and makes sure total sigchecks count is <= | |||||
* MAX_TX_SIGCHECKS_COUNT. Note however that this limit is only in fact | |||||
* effective when the SCRIPT_REPORT_SIGCHECKS flag is enabled. | |||||
*/ | |||||
class TransactionMetricsAccumulator { | |||||
deadalnix: I'm not convinced this is the best place, especially since it could be opaque in this header. | |||||
public: | |||||
using CounterType = int; | |||||
deadalnixUnsubmitted Not Done Inline ActionsIf this the responsibility of the class to handle its innards, then why this? You'll note that this is simply communicating infos to the outside, because there are actually nothing enforcing that it is used in the inside. This does seems to be achieving anything. deadalnix: If this the responsibility of the class to handle its innards, then why this? You'll note that… | |||||
private: | |||||
std::atomic<CounterType> nSigChecks; | |||||
void Set(CounterType _nSigChecks) { | |||||
nSigChecks.store(_nSigChecks, std::memory_order_relaxed); | |||||
} | |||||
public: | |||||
TransactionMetricsAccumulator() { Set(0); } | |||||
void Reset() { Set(0); } | |||||
// Accumulate metrics as obtained from VerifyScript; return true/false | |||||
// whether the resulting accumulation is still within limits. | |||||
bool CheckedAccumulate(ScriptExecutionMetrics metrics); | |||||
// Obtain sigchecks count. This will be <= MAX_TX_SIGCHECKS_COUNT iff | |||||
// no CheckedAccumulate calls returned false. | |||||
CounterType GetSigChecks() { | |||||
return nSigChecks.load(std::memory_order_relaxed); | |||||
} | |||||
}; | |||||
/** | |||||
* Triple responsibility class: | |||||
* - Mostly is a closure representing one input's script verification, but also, | |||||
* - (optionally) has responsibility to update the containing transaction's | |||||
* metrics accumulator, and, | |||||
* - (TODO) has responsibiltiy to update the containing block's metrics | |||||
* accumulator. | |||||
* | |||||
* Note that this stores references to the spending transaction and | |||||
* the accumulator. | |||||
*/ | */ | ||||
class CScriptCheck { | class CScriptCheck { | ||||
private: | private: | ||||
CScript scriptPubKey; | CScript scriptPubKey; | ||||
Amount amount; | Amount amount; | ||||
const CTransaction *ptxTo; | const CTransaction *ptxTo; | ||||
unsigned int nIn; | unsigned int nIn; | ||||
uint32_t nFlags; | uint32_t nFlags; | ||||
bool cacheStore; | bool cacheStore; | ||||
ScriptError error; | ScriptError error; | ||||
ScriptExecutionMetrics metrics; | ScriptExecutionMetrics metrics; | ||||
PrecomputedTransactionData txdata; | PrecomputedTransactionData txdata; | ||||
TransactionMetricsAccumulator *pTxAccumulator; | |||||
public: | public: | ||||
CScriptCheck() | CScriptCheck() | ||||
: amount(), ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), | : amount(), ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), | ||||
error(ScriptError::UNKNOWN), txdata() {} | error(ScriptError::UNKNOWN), txdata(), pTxAccumulator(nullptr) {} | ||||
CScriptCheck(const CScript &scriptPubKeyIn, const Amount amountIn, | CScriptCheck(const CScript &scriptPubKeyIn, const Amount amountIn, | ||||
const CTransaction &txToIn, unsigned int nInIn, | const CTransaction &txToIn, unsigned int nInIn, | ||||
uint32_t nFlagsIn, bool cacheIn, | uint32_t nFlagsIn, bool cacheIn, | ||||
const PrecomputedTransactionData &txdataIn) | const PrecomputedTransactionData &txdataIn, | ||||
TransactionMetricsAccumulator *pTxAccumulatorIn = nullptr) | |||||
: scriptPubKey(scriptPubKeyIn), amount(amountIn), ptxTo(&txToIn), | : scriptPubKey(scriptPubKeyIn), amount(amountIn), ptxTo(&txToIn), | ||||
nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), | nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), | ||||
error(ScriptError::UNKNOWN), txdata(txdataIn) {} | error(ScriptError::UNKNOWN), txdata(txdataIn), | ||||
pTxAccumulator(pTxAccumulatorIn) {} | |||||
bool operator()(); | bool operator()(); | ||||
void swap(CScriptCheck &check) { | void swap(CScriptCheck &check) { | ||||
scriptPubKey.swap(check.scriptPubKey); | scriptPubKey.swap(check.scriptPubKey); | ||||
std::swap(ptxTo, check.ptxTo); | std::swap(ptxTo, check.ptxTo); | ||||
std::swap(amount, check.amount); | std::swap(amount, check.amount); | ||||
std::swap(nIn, check.nIn); | std::swap(nIn, check.nIn); | ||||
std::swap(nFlags, check.nFlags); | std::swap(nFlags, check.nFlags); | ||||
std::swap(cacheStore, check.cacheStore); | std::swap(cacheStore, check.cacheStore); | ||||
std::swap(error, check.error); | std::swap(error, check.error); | ||||
std::swap(txdata, check.txdata); | std::swap(txdata, check.txdata); | ||||
std::swap(pTxAccumulator, check.pTxAccumulator); | |||||
} | } | ||||
ScriptError GetScriptError() const { return error; } | ScriptError GetScriptError() const { return error; } | ||||
ScriptExecutionMetrics GetScriptExecutionMetrics() const { return metrics; } | ScriptExecutionMetrics GetScriptExecutionMetrics() const { return metrics; } | ||||
}; | }; | ||||
/** Functions for disk access for blocks */ | /** Functions for disk access for blocks */ | ||||
▲ Show 20 Lines • Show All 159 Lines • Show Last 20 Lines |
I'm not convinced this is the best place, especially since it could be opaque in this header.