Includes basic refactor.
No-need to calculate the GetMedianTimePast() value twice.
Includes basic refactor.
No-need to calculate the GetMedianTimePast() value twice.
More importantly, there is this question to be answered https://github.com/bitcoin/bips/commit/60d4b512b8ca9d57b479a5ee63c6825415ac0b20#commitcomment-21581456
42 | - pindex->GetMedianTimePast() <= 1510704000 && // Wed 15 Nov 2017 00:00:00 UTC 43 | - !IsWitnessEnabled(pindex->pprev, chainparams.GetConsensus())) 44 | +int64_t nMedianTimePast = pindex->GetMedianTimePast(); 45 | +if ( (nMedianTimePast >= 1506816000) && // Sun Oct 1 00:00:00 UTC 2017 46 | + (nMedianTimePast <= 1510704000) && // Sun Nov 15 00:00:00 UTC 2017 47 | + (!IsWitnessLockedIn(pindex->pprev, chainparams.GetConsensus()) && // Segwit is not locked in
This must be defined in the code example.
37 | @@ -38,13 +38,15 @@ While this BIP is active, all blocks must set the nVersion header top 3 bits to 38 | 39 | <pre> 40 | // 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())) 44 | +int64_t nMedianTimePast = pindex->GetMedianTimePast(); 45 | +if ( (nMedianTimePast >= 1506816000) && // Sun Oct 1 00:00:00 UTC 2017
Both timestamp and date are wrong;
37 | @@ -38,13 +38,15 @@ While this BIP is active, all blocks must set the nVersion header top 3 bits to 38 | 39 | <pre> 40 | // 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())) 44 | +int64_t nMedianTimePast = pindex->GetMedianTimePast(); 45 | +if ( (nMedianTimePast >= 1506816000) && // Sun Oct 1 00:00:00 UTC 2017 46 | + (nMedianTimePast <= 1510704000) && // Sun Nov 15 00:00:00 UTC 2017
Day is wrong, it's Weds not Sun
No-need to calculate the GetMedianTimePast() value twice.
@shaolinfry sorry about that: that was embarrassing. 😳
43 | - pindex->GetMedianTimePast() <= 1510704000 && // Wed 15 Nov 2017 00:00:00 UTC 44 | - !IsWitnessEnabled(pindex->pprev, chainparams.GetConsensus())) 45 | +int64_t nMedianTimePast = pindex->GetMedianTimePast(); 46 | +if ( (nMedianTimePast >= 1501545600) && // Tue 01 Aug 2017 00:00:00 UTC 47 | + (nMedianTimePast <= 1510704000) && // Wed 15 Nov 2017 00:00:00 UTC 48 | + (!IsWitnessLockedIn(pindex->pprev, chainparams.GetConsensus()) && // Segwit is not locked in
You need to define this function since it does not exist in Bitcoin Core.
Done :)
37 | 38 | === Reference implementation === 39 | 40 | <pre> 41 | + 42 | +
two unnecessary lines
46 | + LOCK(cs_main); 47 | + return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) 48 | + == THRESHOLD_LOCKED_IN); 49 | +} 50 | + 51 | +
one unnecessary blank line
43 | +// Check if Segregated Witness is Locked In 44 | +bool IsWitnessLockedIn(const CBlockIndex* pindexPrev, const Consensus::Params& params) 45 | +{ 46 | + LOCK(cs_main); 47 | + return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) 48 | + == THRESHOLD_LOCKED_IN);
dont linebreak here please.
@dooglus comments please?
Sorry, away from computer now. I can fix in a couple of hours.
Sent from my iPhone
On 4 Apr 2017, at 13:55, shaolinfry notifications@github.com wrote:
@shaolinfry requested changes on this pull request.
In bip-0148.mediawiki:
While this BIP is active, all blocks must set the nVersion header top 3 bits to 001 together with bit field (1<<1) (according to the existing segwit deployment). Blocks that do not signal as required will be rejected.
=== Reference implementation ===
<pre> + + two unnecessary lines In bip-0148.mediawiki: > While this BIP is active, all blocks must set the nVersion header top 3 bits to 001 together with bit field (1<<1) (according to the existing segwit deployment). Blocks that do not signal as required will be rejected. === Reference implementation === <pre> + + +// Check if Segregated Witness is Locked In +bool IsWitnessLockedIn(const CBlockIndex* pindexPrev, const Consensus::Params& params) +{ + LOCK(cs_main); + return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) + == THRESHOLD_LOCKED_IN); +} + + one unnecessary blank line In bip-0148.mediawiki: > While this BIP is active, all blocks must set the nVersion header top 3 bits to 001 together with bit field (1<<1) (according to the existing segwit deployment). Blocks that do not signal as required will be rejected. === Reference implementation === <pre> + + +// Check if Segregated Witness is Locked In +bool IsWitnessLockedIn(const CBlockIndex* pindexPrev, const Consensus::Params& params) +{ + LOCK(cs_main); + return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) + == THRESHOLD_LOCKED_IN); dont linebreak here please. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
@da2ce7 If you merge this it'll update this PR with the requested changes: https://github.com/da2ce7/bips/pull/2/files
56 | + !IsWitnessEnabled(pindex->pprev, chainparams.GetConsensus())) ) // and is not active. 57 | { 58 | - // versionbits topbit and segwit flag must be set. 59 | - if ((pindex->nVersion & VERSIONBITS_TOP_MASK) != VERSIONBITS_TOP_BITS || 60 | - (pindex->nVersion & VersionBitsMask(chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT)) == 0) { 61 | + bool fVersionBits = (pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS; // BIP9 bit set
Remove the inaccurate comment.
29 | @@ -30,21 +30,34 @@ It is hoped that miners will respond to this BIP by activating segwit early, bef 30 | 31 | All times are specified according to median past time. 32 | 33 | -This BIP will be activate between midnight August 1st 2017 (epoch time 1501545600) and midnight November 15th 2017 (epoch time 1510704000) if the existing segwit deployment is not activated before epoch time 1501545600. This BIP will cease to be active when the existing segwit deployment activates. 34 | +This BIP will be activate between midnight August 1st 2017 (epoch time 1501545600) and midnight November 15th 2017 (epoch time 1510704000) if the existing segwit deployment is not locked-in or activated before epoch time 1501545600. This BIP will cease to be active when segwit is locked-in.
Should be "This BIP will be active between..."
Bitcoin Branch that implements BIP 148 as described by this pull request. https://github.com/da2ce7/bitcoin/tree/bip148
@shaolinfry, can you please re-review this pull request?
58 | - // versionbits topbit and segwit flag must be set. 59 | - if ((pindex->nVersion & VERSIONBITS_TOP_MASK) != VERSIONBITS_TOP_BITS || 60 | - (pindex->nVersion & VersionBitsMask(chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT)) == 0) { 61 | + bool fVersionBits = (pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS; 62 | + bool fSegbit = (pindex->nVersion & VersionBitsMask(chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT)) != 0; 63 | + if (!(fVersionBits && fSegbit)) {
I thought I had commented here but seems I didn't press the button :) So while it is bikeshedding, I dislike this formatting, and prefer the previous notation but that is just my personal taste. So long as the logic works :)
IMO this way is cleaner.
I need other's to peer review ACK this first, because when I give mine, it will get merged. I'm reasonably confident this is ok now, but peers please.
(Code review should really be done on a code project rather than the BIP change itself.)