Skip to content

Commit 5441106

Browse files
authored
Merge pull request #17 from btc1/2017_bip91
BIP91 SegWit2x activation
2 parents f3fbd6d + 50b9058 commit 5441106

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

src/chainparams.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ class CMainParams : public CChainParams {
9696
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1479168000; // November 15th, 2016.
9797
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1510704000; // November 15th, 2017.
9898

99+
// Deployment of SEGWIT2X
100+
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT2X].bit = 4;
101+
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT2X].nStartTime = 1496275200; // June 1st, 2017.
102+
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT2X].nTimeout = 1510704000; // November 15th, 2017.
103+
99104
// The best chain should have at least this much work.
100105
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000003f94d1ad391682fe038bf5");
101106

src/consensus/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum DeploymentPos
1717
DEPLOYMENT_TESTDUMMY,
1818
DEPLOYMENT_CSV, // Deployment of BIP68, BIP112, and BIP113.
1919
DEPLOYMENT_SEGWIT, // Deployment of BIP141, BIP143, and BIP147.
20+
DEPLOYMENT_SEGWIT2X, // Deployment of SEGWIT2X
2021
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp
2122
MAX_VERSION_BITS_DEPLOYMENTS
2223
};

src/rpc/blockchain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
11351135
softforks.push_back(SoftForkDesc("bip65", 4, tip, consensusParams));
11361136
BIP9SoftForkDescPushBack(bip9_softforks, "csv", consensusParams, Consensus::DEPLOYMENT_CSV);
11371137
BIP9SoftForkDescPushBack(bip9_softforks, "segwit", consensusParams, Consensus::DEPLOYMENT_SEGWIT);
1138+
BIP9SoftForkDescPushBack(bip9_softforks, "segwit2x", consensusParams, Consensus::DEPLOYMENT_SEGWIT2X);
11381139
obj.push_back(Pair("softforks", softforks));
11391140
obj.push_back(Pair("bip9_softforks", bip9_softforks));
11401141

src/validation.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,18 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
18511851
flags |= SCRIPT_VERIFY_NULLDUMMY;
18521852
}
18531853

1854+
// SEGWIT2X signalling.
1855+
if ( VersionBitsState(pindex->pprev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT2X, versionbitscache) == THRESHOLD_ACTIVE &&
1856+
!IsWitnessLockedIn(pindex->pprev, chainparams.GetConsensus()) && // Segwit is not locked in
1857+
!IsWitnessEnabled(pindex->pprev, chainparams.GetConsensus()) ) // and is not active.
1858+
{
1859+
bool fVersionBits = (pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS;
1860+
bool fSegbit = (pindex->nVersion & VersionBitsMask(chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT)) != 0;
1861+
if (!(fVersionBits && fSegbit)) {
1862+
return state.DoS(0, error("ConnectBlock(): relayed block must signal for segwit, please upgrade"), REJECT_INVALID, "bad-no-segwit");
1863+
}
1864+
}
1865+
18541866
int64_t nTime2 = GetTimeMicros(); nTimeForks += nTime2 - nTime1;
18551867
LogPrint("bench", " - Fork checks: %.2fms [%.2fs]\n", 0.001 * (nTime2 - nTime1), nTimeForks * 0.000001);
18561868

@@ -2918,6 +2930,13 @@ bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& pa
29182930
return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == THRESHOLD_ACTIVE);
29192931
}
29202932

2933+
// Check if Segregated Witness is Locked In
2934+
bool IsWitnessLockedIn(const CBlockIndex* pindexPrev, const Consensus::Params& params)
2935+
{
2936+
LOCK(cs_main);
2937+
return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == THRESHOLD_LOCKED_IN);
2938+
}
2939+
29212940
// Compute at which vout of the block's coinbase transaction the witness
29222941
// commitment occurs, or -1 if not found.
29232942
static int GetWitnessCommitmentIndex(const CBlock& block)

src/validation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,9 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams,
503503
/** Check whether witness commitments are required for block. */
504504
bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
505505

506+
/** Check whether witness commitments are required for block. */
507+
bool IsWitnessLockedIn(const CBlockIndex* pindexPrev, const Consensus::Params& params);
508+
506509
/** When there are blocks in the active chain with missing data, rewind the chainstate and remove them from the block index */
507510
bool RewindBlockIndex(const CChainParams& params);
508511

src/versionbits.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION
1818
{
1919
/*.name =*/ "segwit",
2020
/*.gbt_force =*/ true,
21+
},
22+
{
23+
/*.name =*/ "segwit2x",
24+
/*.gbt_force =*/ true,
2125
}
2226
};
2327

@@ -148,7 +152,14 @@ class VersionBitsConditionChecker : public AbstractThresholdConditionChecker {
148152
int64_t BeginTime(const Consensus::Params& params) const { return params.vDeployments[id].nStartTime; }
149153
int64_t EndTime(const Consensus::Params& params) const { return params.vDeployments[id].nTimeout; }
150154
int Period(const Consensus::Params& params) const { return params.nMinerConfirmationWindow; }
151-
int Threshold(const Consensus::Params& params) const { return params.nRuleChangeActivationThreshold; }
155+
int Threshold(const Consensus::Params& params) const {
156+
if (params.nRuleChangeActivationThreshold == 1916 && params.nMinerConfirmationWindow == 2016 &&
157+
params.vDeployments[id].bit == params.vDeployments[Consensus::DEPLOYMENT_SEGWIT2X].bit &&
158+
params.vDeployments[id].nStartTime == params.vDeployments[Consensus::DEPLOYMENT_SEGWIT2X].nStartTime) {
159+
return 1612; // 80% threshold for SEGWIT2X only
160+
}
161+
return params.nRuleChangeActivationThreshold;
162+
}
152163

153164
bool Condition(const CBlockIndex* pindex, const Consensus::Params& params) const
154165
{

0 commit comments

Comments
 (0)