Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 465 Lines • ▼ Show 20 Lines | static bool IsReplayProtectionEnabled(const Consensus::Params ¶ms, | ||||
const CBlockIndex *pindexPrev) { | const CBlockIndex *pindexPrev) { | ||||
if (pindexPrev == nullptr) { | if (pindexPrev == nullptr) { | ||||
return false; | return false; | ||||
} | } | ||||
return IsReplayProtectionEnabled(params, pindexPrev->GetMedianTimePast()); | return IsReplayProtectionEnabled(params, pindexPrev->GetMedianTimePast()); | ||||
} | } | ||||
static bool | // Returns the script flags which should be checked for mempool admission when | ||||
IsReplayProtectionEnabledForCurrentBlock(const Consensus::Params ¶ms) | // the tip is at the given block. | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | static uint32_t GetStandardScriptFlags(const Consensus::Params ¶ms, | ||||
AssertLockHeld(cs_main); | const CBlockIndex *pindexTip) { | ||||
return IsReplayProtectionEnabled(params, chainActive.Tip()); | uint32_t flags = STANDARD_SCRIPT_VERIFY_FLAGS; | ||||
// We make sure this node will have replay protection during the next hard | |||||
// fork. | |||||
if (IsReplayProtectionEnabled(params, pindexTip)) { | |||||
flags |= SCRIPT_ENABLE_REPLAY_PROTECTION; | |||||
} | |||||
return flags; | |||||
} | } | ||||
// Used to avoid mempool polluting consensus critical paths if CCoinsViewMempool | // Used to avoid mempool polluting consensus critical paths if CCoinsViewMempool | ||||
// were somehow broken and returning the wrong scriptPubKeys | // were somehow broken and returning the wrong scriptPubKeys | ||||
static bool CheckInputsFromMempoolAndCache( | static bool CheckInputsFromMempoolAndCache( | ||||
const CTransaction &tx, CValidationState &state, | const CTransaction &tx, CValidationState &state, | ||||
const CCoinsViewCache &view, const CTxMemPool &pool, const uint32_t flags, | const CCoinsViewCache &view, const CTxMemPool &pool, const uint32_t flags, | ||||
bool cacheSigStore, PrecomputedTransactionData &txdata) | bool cacheSigStore, PrecomputedTransactionData &txdata) | ||||
▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Lines | for (const CTxIn &txin : tx.vin) { | ||||
std::string errString; | std::string errString; | ||||
if (!pool.CalculateMemPoolAncestors( | if (!pool.CalculateMemPoolAncestors( | ||||
entry, setAncestors, nLimitAncestors, nLimitAncestorSize, | entry, setAncestors, nLimitAncestors, nLimitAncestorSize, | ||||
nLimitDescendants, nLimitDescendantSize, errString)) { | nLimitDescendants, nLimitDescendantSize, errString)) { | ||||
return state.DoS(0, false, REJECT_NONSTANDARD, | return state.DoS(0, false, REJECT_NONSTANDARD, | ||||
"too-long-mempool-chain", false, errString); | "too-long-mempool-chain", false, errString); | ||||
} | } | ||||
// Set extraFlags as a set of flags that needs to be activated. | |||||
uint32_t extraFlags = SCRIPT_VERIFY_NONE; | |||||
if (IsReplayProtectionEnabledForCurrentBlock(consensusParams)) { | |||||
extraFlags |= SCRIPT_ENABLE_REPLAY_PROTECTION; | |||||
} | |||||
// Make sure whatever we need to activate is actually activated. | |||||
const uint32_t scriptVerifyFlags = | const uint32_t scriptVerifyFlags = | ||||
STANDARD_SCRIPT_VERIFY_FLAGS | extraFlags; | GetStandardScriptFlags(consensusParams, chainActive.Tip()); | ||||
// Check against previous transactions. This is done last to help | // Check against previous transactions. This is done last to help | ||||
// prevent CPU exhaustion denial-of-service attacks. | // prevent CPU exhaustion denial-of-service attacks. | ||||
PrecomputedTransactionData txdata(tx); | PrecomputedTransactionData txdata(tx); | ||||
if (!CheckInputs(tx, state, view, true, scriptVerifyFlags, true, false, | if (!CheckInputs(tx, state, view, true, scriptVerifyFlags, true, false, | ||||
txdata)) { | txdata)) { | ||||
// State filled in by CheckInputs. | // State filled in by CheckInputs. | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 791 Lines • ▼ Show 20 Lines | |||||
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, | int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, | ||||
const Consensus::Params ¶ms) { | const Consensus::Params ¶ms) { | ||||
int32_t nVersion = VERSIONBITS_TOP_BITS; | int32_t nVersion = VERSIONBITS_TOP_BITS; | ||||
return nVersion; | return nVersion; | ||||
} | } | ||||
// Returns the script flags which should be checked for the block after | // Returns the script flags which should be checked for the block after | ||||
// the given block. | // the given block. | ||||
static uint32_t GetNextBlockScriptFlags(const Consensus::Params ¶ms, | static uint32_t GetNextBlockScriptFlags(const Consensus::Params ¶ms, | ||||
markblundeberg: Other function here, for comparison. | |||||
const CBlockIndex *pindex) { | const CBlockIndex *pindex) { | ||||
uint32_t flags = SCRIPT_VERIFY_NONE; | uint32_t flags = SCRIPT_VERIFY_NONE; | ||||
// Start enforcing P2SH (BIP16) | // Start enforcing P2SH (BIP16) | ||||
if ((pindex->nHeight + 1) >= params.BIP16Height) { | if ((pindex->nHeight + 1) >= params.BIP16Height) { | ||||
flags |= SCRIPT_VERIFY_P2SH; | flags |= SCRIPT_VERIFY_P2SH; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 4,122 Lines • Show Last 20 Lines |
Other function here, for comparison.