Skip to content

Commit 2a97af8

Browse files
committed
Refactor Code-Example with Better Formatting
No-need to calculate the GetMedianTimePast() value twice.
1 parent b7850ab commit 2a97af8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

bip-0148.mediawiki

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ While this BIP is active, all blocks must set the nVersion header top 3 bits to
3838

3939
<pre>
4040
// BIP148 mandatory segwit signalling.
41-
if (pindex->GetMedianTimePast() >= 1501545600 && // Tue 1 Aug 2017 00:00:00 UTC
42-
pindex->GetMedianTimePast() <= 1510704000 && // Wed 15 Nov 2017 00:00:00 UTC
43-
!IsWitnessEnabled(pindex->pprev, chainparams.GetConsensus()))
41+
int64_t nMedianTimePast = pindex->GetMedianTimePast();
42+
if ( (nMedianTimePast >= 1501545600) && // Tue 01 Aug 2017 00:00:00 UTC
43+
(nMedianTimePast <= 1510704000) && // Wed 15 Nov 2017 00:00:00 UTC
44+
(!IsWitnessEnabled(pindex->pprev, chainparams.GetConsensus())) ) // Segwit is not active
4445
{
45-
// versionbits topbit and segwit flag must be set.
46-
if ((pindex->nVersion & VERSIONBITS_TOP_MASK) != VERSIONBITS_TOP_BITS ||
47-
(pindex->nVersion & VersionBitsMask(chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT)) == 0) {
46+
bool fVersionBits = (pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS; // BIP9 bit set
47+
bool fSegbit = (pindex->nVersion & VersionBitsMask(chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT)) != 0; // segwit bit set
48+
if (!(fVersionBits && fSegbit)) {
4849
return state.DoS(0, error("ConnectBlock(): relayed block must signal for segwit, please upgrade"), REJECT_INVALID, "bad-no-segwit");
4950
}
5051
}

0 commit comments

Comments
 (0)