Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
| // Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
| // Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
| // Copyright (c) 2017 The Bitcoin developers | // Copyright (c) 2017-2018 The Bitcoin developers | ||||
| // Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
| #include "validation.h" | #include "validation.h" | ||||
| #include "arith_uint256.h" | #include "arith_uint256.h" | ||||
| #include "chainparams.h" | #include "chainparams.h" | ||||
| #include "checkpoints.h" | #include "checkpoints.h" | ||||
| ▲ Show 20 Lines • Show All 968 Lines • ▼ Show 20 Lines | // Check for conflicts with in-memory transactions | ||||
| 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 = 0; | |||||
| if (IsReplayProtectionEnabledForCurrentBlock(config)) { | |||||
| extraFlags |= SCRIPT_ENABLE_REPLAY_PROTECTION; | |||||
| } | |||||
| // Check inputs based on the set of flags we activate. | |||||
| uint32_t scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS; | uint32_t scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS; | ||||
| if (!config.GetChainParams().RequireStandard()) { | if (!config.GetChainParams().RequireStandard()) { | ||||
| scriptVerifyFlags = | scriptVerifyFlags = | ||||
| SCRIPT_ENABLE_SIGHASH_FORKID | | SCRIPT_ENABLE_SIGHASH_FORKID | | ||||
| gArgs.GetArg("-promiscuousmempoolflags", scriptVerifyFlags); | gArgs.GetArg("-promiscuousmempoolflags", scriptVerifyFlags); | ||||
| } | } | ||||
| const bool hasReplayProtection = | // Make sure whatever we need to activate is actually activated. | ||||
| IsReplayProtectionEnabledForCurrentBlock(config); | scriptVerifyFlags |= extraFlags; | ||||
| if (hasReplayProtection) { | |||||
| scriptVerifyFlags |= SCRIPT_ENABLE_REPLAY_PROTECTION; | |||||
| } | |||||
| // 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 All 11 Lines | // Check for conflicts with in-memory transactions | ||||
| // instance the STRICTENC flag was incorrectly allowing certain CHECKSIG | // instance the STRICTENC flag was incorrectly allowing certain CHECKSIG | ||||
| // NOT scripts to pass, even though they were invalid. | // NOT scripts to pass, even though they were invalid. | ||||
| // | // | ||||
| // There is a similar check in CreateNewBlock() to prevent creating | // There is a similar check in CreateNewBlock() to prevent creating | ||||
| // invalid blocks (using TestBlockValidity), however allowing such | // invalid blocks (using TestBlockValidity), however allowing such | ||||
| // transactions into the mempool can be exploited as a DoS attack. | // transactions into the mempool can be exploited as a DoS attack. | ||||
| uint32_t currentBlockScriptVerifyFlags = | uint32_t currentBlockScriptVerifyFlags = | ||||
| GetBlockScriptFlags(chainActive.Tip(), config); | GetBlockScriptFlags(chainActive.Tip(), config); | ||||
| // We have an off by one error for flag activation. As a result, we need | // We have an off by one error for flag activation. As a result, we need | ||||
| // to set the replay protection flag manually here until this is fixed. | // to set the replay protection flag manually here until this is fixed. | ||||
| // FIXME: https://reviews.bitcoinabc.org/T288 | // FIXME: https://reviews.bitcoinabc.org/T288 | ||||
| if (hasReplayProtection) { | currentBlockScriptVerifyFlags |= extraFlags; | ||||
| currentBlockScriptVerifyFlags |= SCRIPT_ENABLE_REPLAY_PROTECTION; | |||||
| } | |||||
| if (!CheckInputsFromMempoolAndCache(tx, state, view, pool, | if (!CheckInputsFromMempoolAndCache(tx, state, view, pool, | ||||
| currentBlockScriptVerifyFlags, true, | currentBlockScriptVerifyFlags, true, | ||||
| txdata)) { | txdata)) { | ||||
| // If we're using promiscuousmempoolflags, we may hit this normally. | // If we're using promiscuousmempoolflags, we may hit this normally. | ||||
| // Check if current block has some flags that scriptVerifyFlags does | // Check if current block has some flags that scriptVerifyFlags does | ||||
| // not before printing an ominous warning. | // not before printing an ominous warning. | ||||
| if (!(~scriptVerifyFlags & currentBlockScriptVerifyFlags)) { | if (!(~scriptVerifyFlags & currentBlockScriptVerifyFlags)) { | ||||
| return error( | return error( | ||||
| "%s: BUG! PLEASE REPORT THIS! ConnectInputs failed against " | "%s: BUG! PLEASE REPORT THIS! ConnectInputs failed against " | ||||
| "MANDATORY but not STANDARD flags %s, %s", | "MANDATORY but not STANDARD flags %s, %s", | ||||
| __func__, txid.ToString(), FormatStateMessage(state)); | __func__, txid.ToString(), FormatStateMessage(state)); | ||||
| } | } | ||||
| uint32_t mandatoryFlags = MANDATORY_SCRIPT_VERIFY_FLAGS; | if (!CheckInputs(tx, state, view, true, | ||||
| if (hasReplayProtection) { | MANDATORY_SCRIPT_VERIFY_FLAGS | extraFlags, true, | ||||
| mandatoryFlags |= SCRIPT_ENABLE_REPLAY_PROTECTION; | false, txdata)) { | ||||
| } | |||||
| if (!CheckInputs(tx, state, view, true, mandatoryFlags, true, false, | |||||
| txdata)) { | |||||
| return error( | return error( | ||||
| "%s: ConnectInputs failed against MANDATORY but not " | "%s: ConnectInputs failed against MANDATORY but not " | ||||
| "STANDARD flags due to promiscuous mempool %s, %s", | "STANDARD flags due to promiscuous mempool %s, %s", | ||||
| __func__, txid.ToString(), FormatStateMessage(state)); | __func__, txid.ToString(), FormatStateMessage(state)); | ||||
| } | } | ||||
| LogPrintf("Warning: -promiscuousmempool flags set to not include " | LogPrintf("Warning: -promiscuousmempool flags set to not include " | ||||
| "currently enforced soft forks, this may break mining or " | "currently enforced soft forks, this may break mining or " | ||||
| ▲ Show 20 Lines • Show All 4,358 Lines • Show Last 20 Lines | |||||