Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 1,703 Lines • ▼ Show 20 Lines | bool Condition(const CBlockIndex *pindex, | ||||
((pindex->nVersion >> bit) & 1) != 0 && | ((pindex->nVersion >> bit) & 1) != 0 && | ||||
((ComputeBlockVersion(pindex->pprev, params) >> bit) & 1) == 0; | ((ComputeBlockVersion(pindex->pprev, params) >> bit) & 1) == 0; | ||||
} | } | ||||
}; | }; | ||||
// Protected by cs_main | // Protected by cs_main | ||||
static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS]; | static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS]; | ||||
// Returns the script flags which should be checked for a given block | |||||
static uint32_t GetBlockScriptFlags(const CBlockIndex *pindex, | |||||
const Config &config) { | |||||
AssertLockHeld(cs_main); | |||||
const Consensus::Params &consensusparams = | |||||
config.GetChainParams().GetConsensus(); | |||||
// BIP16 didn't become active until Apr 1 2012 | |||||
int64_t nBIP16SwitchTime = 1333238400; | |||||
bool fStrictPayToScriptHash = (pindex->GetBlockTime() >= nBIP16SwitchTime); | |||||
unsigned int flags = | |||||
fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE; | |||||
// Start enforcing the DERSIG (BIP66) rule | |||||
if (pindex->nHeight >= consensusparams.BIP66Height) { | |||||
flags |= SCRIPT_VERIFY_DERSIG; | |||||
} | |||||
// Start enforcing CHECKLOCKTIMEVERIFY (BIP65) rule | |||||
if (pindex->nHeight >= consensusparams.BIP65Height) { | |||||
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; | |||||
} | |||||
// Start enforcing BIP112 (CHECKSEQUENCEVERIFY) using versionbits logic. | |||||
if (VersionBitsState(pindex->pprev, consensusparams, | |||||
Consensus::DEPLOYMENT_CSV, | |||||
versionbitscache) == THRESHOLD_ACTIVE) { | |||||
flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY; | |||||
} | |||||
// If the UAHF is enabled, we start accepting replay protected txns | |||||
if (IsUAHFenabled(config, pindex->pprev)) { | |||||
flags |= SCRIPT_VERIFY_STRICTENC; | |||||
flags |= SCRIPT_ENABLE_SIGHASH_FORKID; | |||||
} | |||||
return flags; | |||||
} | |||||
static int64_t nTimeCheck = 0; | static int64_t nTimeCheck = 0; | ||||
static int64_t nTimeForks = 0; | static int64_t nTimeForks = 0; | ||||
static int64_t nTimeVerify = 0; | static int64_t nTimeVerify = 0; | ||||
static int64_t nTimeConnect = 0; | static int64_t nTimeConnect = 0; | ||||
static int64_t nTimeIndex = 0; | static int64_t nTimeIndex = 0; | ||||
static int64_t nTimeCallbacks = 0; | static int64_t nTimeCallbacks = 0; | ||||
static int64_t nTimeTotal = 0; | static int64_t nTimeTotal = 0; | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | if (fEnforceBIP30) { | ||||
100, | 100, | ||||
error("ConnectBlock(): tried to overwrite transaction"), | error("ConnectBlock(): tried to overwrite transaction"), | ||||
REJECT_INVALID, "bad-txns-BIP30"); | REJECT_INVALID, "bad-txns-BIP30"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// BIP16 didn't become active until Apr 1 2012 | // Start enforcing BIP68 (sequence locks) using versionbits logic. | ||||
int64_t nBIP16SwitchTime = 1333238400; | |||||
bool fStrictPayToScriptHash = (pindex->GetBlockTime() >= nBIP16SwitchTime); | |||||
uint32_t flags = | |||||
fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE; | |||||
// Start enforcing the DERSIG (BIP66) rule | |||||
if (pindex->nHeight >= chainparams.GetConsensus().BIP66Height) { | |||||
flags |= SCRIPT_VERIFY_DERSIG; | |||||
} | |||||
// Start enforcing CHECKLOCKTIMEVERIFY (BIP65) rule | |||||
if (pindex->nHeight >= chainparams.GetConsensus().BIP65Height) { | |||||
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; | |||||
} | |||||
// Start enforcing BIP68 (sequence locks) and BIP112 (CHECKSEQUENCEVERIFY) | |||||
// using versionbits logic. | |||||
int nLockTimeFlags = 0; | int nLockTimeFlags = 0; | ||||
if (VersionBitsState(pindex->pprev, chainparams.GetConsensus(), | if (VersionBitsState(pindex->pprev, chainparams.GetConsensus(), | ||||
Consensus::DEPLOYMENT_CSV, | Consensus::DEPLOYMENT_CSV, | ||||
versionbitscache) == THRESHOLD_ACTIVE) { | versionbitscache) == THRESHOLD_ACTIVE) { | ||||
flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY; | |||||
nLockTimeFlags |= LOCKTIME_VERIFY_SEQUENCE; | nLockTimeFlags |= LOCKTIME_VERIFY_SEQUENCE; | ||||
} | } | ||||
// If the UAHF is enabled, we start accepting replay protected txns | uint32_t flags = GetBlockScriptFlags(pindex, config); | ||||
const bool hasUAHF = IsUAHFenabled(config, pindex->pprev); | |||||
if (hasUAHF) { | |||||
flags |= SCRIPT_VERIFY_STRICTENC; | |||||
flags |= SCRIPT_ENABLE_SIGHASH_FORKID; | |||||
} | |||||
int64_t nTime2 = GetTimeMicros(); | int64_t nTime2 = GetTimeMicros(); | ||||
nTimeForks += nTime2 - nTime1; | nTimeForks += nTime2 - nTime1; | ||||
LogPrint("bench", " - Fork checks: %.2fms [%.2fs]\n", | LogPrint("bench", " - Fork checks: %.2fms [%.2fs]\n", | ||||
0.001 * (nTime2 - nTime1), nTimeForks * 0.000001); | 0.001 * (nTime2 - nTime1), nTimeForks * 0.000001); | ||||
CBlockUndo blockundo; | CBlockUndo blockundo; | ||||
▲ Show 20 Lines • Show All 3,060 Lines • Show Last 20 Lines |