Skip to content

Commit 0328dcd

Browse files
committed
[Consensus] Bury segwit deployment
Hardcode segwit deployment height to 481824 for mainnet.
1 parent 1c93b9b commit 0328dcd

15 files changed

+71
-113
lines changed

src/chainparams.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class CMainParams : public CChainParams {
7070
consensus.BIP65Height = 388381; // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0
7171
consensus.BIP66Height = 363725; // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931
7272
consensus.CSVHeight = 419328; // 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5
73+
consensus.SegwitHeight = 481824; // 0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893
7374
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
7475
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
7576
consensus.nPowTargetSpacing = 10 * 60;
@@ -81,11 +82,6 @@ class CMainParams : public CChainParams {
8182
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
8283
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
8384

84-
// Deployment of SegWit (BIP141, BIP143, and BIP147)
85-
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
86-
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1479168000; // November 15th, 2016.
87-
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1510704000; // November 15th, 2017.
88-
8985
// The best chain should have at least this much work.
9086
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000051dc8b82f450202ecb3d471");
9187

@@ -180,6 +176,7 @@ class CTestNetParams : public CChainParams {
180176
consensus.BIP65Height = 581885; // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
181177
consensus.BIP66Height = 330776; // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182
182178
consensus.CSVHeight = 770112; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb
179+
consensus.SegwitHeight = 834624; // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca
183180
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
184181
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
185182
consensus.nPowTargetSpacing = 10 * 60;
@@ -191,11 +188,6 @@ class CTestNetParams : public CChainParams {
191188
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
192189
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
193190

194-
// Deployment of SegWit (BIP141, BIP143, and BIP147)
195-
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
196-
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1462060800; // May 1st 2016
197-
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1493596800; // May 1st 2017
198-
199191
// The best chain should have at least this much work.
200192
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000007dbe94253893cbd463");
201193

@@ -268,6 +260,7 @@ class CRegTestParams : public CChainParams {
268260
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in functional tests)
269261
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in functional tests)
270262
consensus.CSVHeight = 432; // CSV activated on regtest (Used in rpc activation tests)
263+
consensus.SegwitHeight = 0; // SEGWIT is always activated on regtest unless overridden
271264
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
272265
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
273266
consensus.nPowTargetSpacing = 10 * 60;
@@ -278,9 +271,6 @@ class CRegTestParams : public CChainParams {
278271
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
279272
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
280273
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
281-
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
282-
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = Consensus::BIP9Deployment::ALWAYS_ACTIVE;
283-
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
284274

285275
// The best chain should have at least this much work.
286276
consensus.nMinimumChainWork = uint256S("0x00");
@@ -297,7 +287,7 @@ class CRegTestParams : public CChainParams {
297287
m_assumed_blockchain_size = 0;
298288
m_assumed_chain_state_size = 0;
299289

300-
UpdateVersionBitsParametersFromArgs(args);
290+
UpdateActivationParametersFromArgs(args);
301291

302292
genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN);
303293
consensus.hashGenesisBlock = genesis.GetHash();
@@ -340,11 +330,22 @@ class CRegTestParams : public CChainParams {
340330
consensus.vDeployments[d].nStartTime = nStartTime;
341331
consensus.vDeployments[d].nTimeout = nTimeout;
342332
}
343-
void UpdateVersionBitsParametersFromArgs(const ArgsManager& args);
333+
void UpdateActivationParametersFromArgs(const ArgsManager& args);
344334
};
345335

346-
void CRegTestParams::UpdateVersionBitsParametersFromArgs(const ArgsManager& args)
336+
void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
347337
{
338+
if (gArgs.IsArgSet("-segwitheight")) {
339+
int64_t height = gArgs.GetArg("-segwitheight", consensus.SegwitHeight);
340+
if (height < -1 || height >= std::numeric_limits<int>::max()) {
341+
throw std::runtime_error(strprintf("Activation height %ld for segwit is out of valid range. Use -1 to disable segwit.", height));
342+
} else if (height == -1) {
343+
LogPrintf("Segwit disabled for testing\n");
344+
height = std::numeric_limits<int>::max();
345+
}
346+
consensus.SegwitHeight = static_cast<int>(height);
347+
}
348+
348349
if (!args.IsArgSet("-vbparams")) return;
349350

350351
for (const std::string& strDeployment : args.GetArgs("-vbparams")) {

src/chainparamsbase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void SetupChainParamsBaseOptions()
1919
{
2020
gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
2121
"This is intended for regression testing tools and app development.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
22+
gArgs.AddArg("-segwitheight=<n>", "Set the activation height of segwit. -1 to disable. (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
2223
gArgs.AddArg("-testnet", "Use the test chain", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
2324
gArgs.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
2425
}

src/consensus/params.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace Consensus {
1616
enum DeploymentPos
1717
{
1818
DEPLOYMENT_TESTDUMMY,
19-
DEPLOYMENT_SEGWIT, // Deployment of BIP141, BIP143, and BIP147.
2019
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp
2120
MAX_VERSION_BITS_DEPLOYMENTS
2221
};
@@ -59,6 +58,10 @@ struct Params {
5958
int BIP66Height;
6059
/** Block height at which CSV (BIP68, BIP112 and BIP113) becomes active */
6160
int CSVHeight;
61+
/** Block height at which Segwit (BIP141, BIP143 and BIP147) becomes active.
62+
* Note that segwit v0 script rules are enforced on all blocks except the
63+
* BIP 16 exception blocks. */
64+
int SegwitHeight;
6265
/**
6366
* Minimum blocks including miner confirmation of the total of 2016 blocks in a retargeting period,
6467
* (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments.

src/init.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,12 +1670,9 @@ bool AppInitMain(InitInterfaces& interfaces)
16701670
}
16711671
}
16721672

1673-
if (chainparams.GetConsensus().vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0) {
1674-
// Only advertise witness capabilities if they have a reasonable start time.
1675-
// This allows us to have the code merged without a defined softfork, by setting its
1676-
// end time to 0.
1677-
// Note that setting NODE_WITNESS is never required: the only downside from not
1678-
// doing so is that after activation, no upgraded nodes will fetch from you.
1673+
if (chainparams.GetConsensus().SegwitHeight != std::numeric_limits<int>::max()) {
1674+
// Advertise witness capabilities.
1675+
// The option to not set NODE_WITNESS is only used in the tests and should be removed.
16791676
nLocalServices = ServiceFlags(nLocalServices | NODE_WITNESS);
16801677
}
16811678

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
13381338
BuriedForkDescPushBack(softforks, "bip66", consensusParams.BIP66Height);
13391339
BuriedForkDescPushBack(softforks, "bip65", consensusParams.BIP65Height);
13401340
BuriedForkDescPushBack(softforks, "csv", consensusParams.CSVHeight);
1341-
BIP9SoftForkDescPushBack(softforks, "segwit", consensusParams, Consensus::DEPLOYMENT_SEGWIT);
1341+
BuriedForkDescPushBack(softforks, "segwit", consensusParams.SegwitHeight);
13421342
BIP9SoftForkDescPushBack(softforks, "testdummy", consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
13431343
obj.pushKV("softforks", softforks);
13441344

src/rpc/mining.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
482482
// TODO: Maybe recheck connections/IBD and (if something wrong) send an expires-immediately template to stop miners?
483483
}
484484

485-
const struct VBDeploymentInfo& segwit_info = VersionBitsDeploymentInfo[Consensus::DEPLOYMENT_SEGWIT];
486485
// GBT must be called with 'segwit' set in the rules
487-
if (setClientRules.count(segwit_info.name) != 1) {
486+
if (setClientRules.count("segwit") != 1) {
488487
throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the segwit rule set (call with {\"rules\": [\"segwit\"]})");
489488
}
490489

@@ -521,7 +520,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
521520
pblock->nNonce = 0;
522521

523522
// NOTE: If at some point we support pre-segwit miners post-segwit-activation, this needs to take segwit support into consideration
524-
const bool fPreSegWit = (ThresholdState::ACTIVE != VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache));
523+
const bool fPreSegWit = (pindexPrev->nHeight + 1 < consensusParams.SegwitHeight);
525524

526525
UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
527526

src/test/setup_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ TestChain100Setup::TestChain100Setup() : TestingSetup(CBaseChainParams::REGTEST)
122122
{
123123
// CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests.
124124
// TODO: fix the code to support SegWit blocks.
125-
gArgs.ForceSetArg("-vbparams", strprintf("segwit:0:%d", (int64_t)Consensus::BIP9Deployment::NO_TIMEOUT));
125+
gArgs.ForceSetArg("-segwitheight", "432");
126126
SelectParams(CBaseChainParams::REGTEST);
127127

128128
// Generate a 100-block chain:

src/validation.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS] GUARDED_BY(cs_
16081608
// environment. See test/functional/p2p-segwit.py.
16091609
static bool IsScriptWitnessEnabled(const Consensus::Params& params)
16101610
{
1611-
return params.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0;
1611+
return params.SegwitHeight != std::numeric_limits<int>::max();
16121612
}
16131613

16141614
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& consensusparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
@@ -1649,7 +1649,8 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
16491649
flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
16501650
}
16511651

1652-
if (IsNullDummyEnabled(pindex->pprev, consensusparams)) {
1652+
// Start enforcing BIP147 NULLDUMMY (activated simultaneously with segwit)
1653+
if (IsWitnessEnabled(pindex->pprev, consensusparams)) {
16531654
flags |= SCRIPT_VERIFY_NULLDUMMY;
16541655
}
16551656

@@ -3045,14 +3046,8 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
30453046

30463047
bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params)
30473048
{
3048-
LOCK(cs_main);
3049-
return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == ThresholdState::ACTIVE);
3050-
}
3051-
3052-
bool IsNullDummyEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params)
3053-
{
3054-
LOCK(cs_main);
3055-
return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == ThresholdState::ACTIVE);
3049+
int height = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1;
3050+
return (height >= params.SegwitHeight);
30563051
}
30573052

30583053
// Compute at which vout of the block's coinbase transaction the witness
@@ -3087,7 +3082,7 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
30873082
std::vector<unsigned char> commitment;
30883083
int commitpos = GetWitnessCommitmentIndex(block);
30893084
std::vector<unsigned char> ret(32, 0x00);
3090-
if (consensusParams.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0) {
3085+
if (consensusParams.SegwitHeight != std::numeric_limits<int>::max()) {
30913086
if (commitpos == -1) {
30923087
uint256 witnessroot = BlockWitnessMerkleRoot(block, nullptr);
30933088
CHash256().Write(witnessroot.begin(), 32).Write(ret.data(), 32).Finalize(witnessroot.begin());
@@ -3222,7 +3217,7 @@ static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, c
32223217
// {0xaa, 0x21, 0xa9, 0xed}, and the following 32 bytes are SHA256^2(witness root, witness reserved value). In case there are
32233218
// multiple, the last one is used.
32243219
bool fHaveWitness = false;
3225-
if (VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == ThresholdState::ACTIVE) {
3220+
if (nHeight >= consensusParams.SegwitHeight) {
32263221
int commitpos = GetWitnessCommitmentIndex(block);
32273222
if (commitpos != -1) {
32283223
bool malleated = false;

src/validation.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,10 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
383383
/** Check a block is completely valid from start to finish (only works on top of our current best block) */
384384
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
385385

386-
/** Check whether witness commitments are required for block. */
386+
/** Check whether witness commitments are required for a block, and whether to enforce NULLDUMMY (BIP 147) rules.
387+
* Note that transaction witness validation rules are always enforced when P2SH is enforced. */
387388
bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
388389

389-
/** Check whether NULLDUMMY (BIP 147) has activated. */
390-
bool IsNullDummyEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
391-
392390
/** When there are blocks in the active chain with missing data, rewind the chainstate and remove them from the block index */
393391
bool RewindBlockIndex(const CChainParams& params) LOCKS_EXCLUDED(cs_main);
394392

src/versionbitsinfo.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,4 @@ const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_B
1111
/*.name =*/ "testdummy",
1212
/*.gbt_force =*/ true,
1313
},
14-
{
15-
/*.name =*/ "segwit",
16-
/*.gbt_force =*/ true,
17-
}
1814
};

0 commit comments

Comments
 (0)