@@ -312,6 +312,9 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool
312
312
return EvaluateSequenceLocks (index, lockPair);
313
313
}
314
314
315
+ // Returns the script flags which should be checked for a given block
316
+ static unsigned int GetBlockScriptFlags (const CBlockIndex* pindex, const Consensus::Params& chainparams);
317
+
315
318
static void LimitMempoolSize (CTxMemPool& pool, size_t limit, unsigned long age) {
316
319
int expired = pool.Expire (GetTime () - age);
317
320
if (expired != 0 ) {
@@ -1475,6 +1478,41 @@ class WarningBitsConditionChecker : public AbstractThresholdConditionChecker
1475
1478
// Protected by cs_main
1476
1479
static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS];
1477
1480
1481
+ static unsigned int GetBlockScriptFlags (const CBlockIndex* pindex, const Consensus::Params& consensusparams) {
1482
+ AssertLockHeld (cs_main);
1483
+
1484
+ // BIP16 didn't become active until Apr 1 2012
1485
+ int64_t nBIP16SwitchTime = 1333238400 ;
1486
+ bool fStrictPayToScriptHash = (pindex->GetBlockTime () >= nBIP16SwitchTime);
1487
+
1488
+ unsigned int flags = fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE;
1489
+
1490
+ // Start enforcing the DERSIG (BIP66) rule
1491
+ if (pindex->nHeight >= consensusparams.BIP66Height ) {
1492
+ flags |= SCRIPT_VERIFY_DERSIG;
1493
+ }
1494
+
1495
+ // Start enforcing CHECKLOCKTIMEVERIFY (BIP65) rule
1496
+ if (pindex->nHeight >= consensusparams.BIP65Height ) {
1497
+ flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
1498
+ }
1499
+
1500
+ // Start enforcing BIP68 (sequence locks) and BIP112 (CHECKSEQUENCEVERIFY) using versionbits logic.
1501
+ if (VersionBitsState (pindex->pprev , consensusparams, Consensus::DEPLOYMENT_CSV, versionbitscache) == THRESHOLD_ACTIVE) {
1502
+ flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
1503
+ }
1504
+
1505
+ // Start enforcing WITNESS rules using versionbits logic.
1506
+ if (IsWitnessEnabled (pindex->pprev , consensusparams)) {
1507
+ flags |= SCRIPT_VERIFY_WITNESS;
1508
+ flags |= SCRIPT_VERIFY_NULLDUMMY;
1509
+ }
1510
+
1511
+ return flags;
1512
+ }
1513
+
1514
+
1515
+
1478
1516
static int64_t nTimeCheck = 0 ;
1479
1517
static int64_t nTimeForks = 0 ;
1480
1518
static int64_t nTimeVerify = 0 ;
@@ -1578,34 +1616,14 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
1578
1616
}
1579
1617
}
1580
1618
1581
- // BIP16 didn't become active until Apr 1 2012
1582
- int64_t nBIP16SwitchTime = 1333238400 ;
1583
- bool fStrictPayToScriptHash = (pindex->GetBlockTime () >= nBIP16SwitchTime);
1584
-
1585
- unsigned int flags = fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE;
1586
-
1587
- // Start enforcing the DERSIG (BIP66) rule
1588
- if (pindex->nHeight >= chainparams.GetConsensus ().BIP66Height ) {
1589
- flags |= SCRIPT_VERIFY_DERSIG;
1590
- }
1591
-
1592
- // Start enforcing CHECKLOCKTIMEVERIFY (BIP65) rule
1593
- if (pindex->nHeight >= chainparams.GetConsensus ().BIP65Height ) {
1594
- flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
1595
- }
1596
-
1597
1619
// Start enforcing BIP68 (sequence locks) and BIP112 (CHECKSEQUENCEVERIFY) using versionbits logic.
1598
1620
int nLockTimeFlags = 0 ;
1599
1621
if (VersionBitsState (pindex->pprev , chainparams.GetConsensus (), Consensus::DEPLOYMENT_CSV, versionbitscache) == THRESHOLD_ACTIVE) {
1600
- flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
1601
1622
nLockTimeFlags |= LOCKTIME_VERIFY_SEQUENCE;
1602
1623
}
1603
1624
1604
- // Start enforcing WITNESS rules using versionbits logic.
1605
- if (IsWitnessEnabled (pindex->pprev , chainparams.GetConsensus ())) {
1606
- flags |= SCRIPT_VERIFY_WITNESS;
1607
- flags |= SCRIPT_VERIFY_NULLDUMMY;
1608
- }
1625
+ // Get the script flags for this block
1626
+ unsigned int flags = GetBlockScriptFlags (pindex, chainparams.GetConsensus ());
1609
1627
1610
1628
int64_t nTime2 = GetTimeMicros (); nTimeForks += nTime2 - nTime1;
1611
1629
LogPrint (BCLog::BENCH, " - Fork checks: %.2fms [%.2fs]\n " , 0.001 * (nTime2 - nTime1), nTimeForks * 0.000001 );
0 commit comments