[Consensus] Bury segwit deployment
Hardcode segwit deployment height to 481824 for mainnet.
This commit is contained in:
parent
1c93b9b31c
commit
0328dcdcfc
15 changed files with 71 additions and 113 deletions
|
@ -70,6 +70,7 @@ public:
|
|||
consensus.BIP65Height = 388381; // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0
|
||||
consensus.BIP66Height = 363725; // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931
|
||||
consensus.CSVHeight = 419328; // 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5
|
||||
consensus.SegwitHeight = 481824; // 0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893
|
||||
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
|
||||
consensus.nPowTargetSpacing = 10 * 60;
|
||||
|
@ -81,11 +82,6 @@ public:
|
|||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
|
||||
|
||||
// Deployment of SegWit (BIP141, BIP143, and BIP147)
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1479168000; // November 15th, 2016.
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1510704000; // November 15th, 2017.
|
||||
|
||||
// The best chain should have at least this much work.
|
||||
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000051dc8b82f450202ecb3d471");
|
||||
|
||||
|
@ -180,6 +176,7 @@ public:
|
|||
consensus.BIP65Height = 581885; // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
|
||||
consensus.BIP66Height = 330776; // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182
|
||||
consensus.CSVHeight = 770112; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb
|
||||
consensus.SegwitHeight = 834624; // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca
|
||||
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
|
||||
consensus.nPowTargetSpacing = 10 * 60;
|
||||
|
@ -191,11 +188,6 @@ public:
|
|||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
|
||||
|
||||
// Deployment of SegWit (BIP141, BIP143, and BIP147)
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1462060800; // May 1st 2016
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1493596800; // May 1st 2017
|
||||
|
||||
// The best chain should have at least this much work.
|
||||
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000007dbe94253893cbd463");
|
||||
|
||||
|
@ -268,6 +260,7 @@ public:
|
|||
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in functional tests)
|
||||
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in functional tests)
|
||||
consensus.CSVHeight = 432; // CSV activated on regtest (Used in rpc activation tests)
|
||||
consensus.SegwitHeight = 0; // SEGWIT is always activated on regtest unless overridden
|
||||
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
|
||||
consensus.nPowTargetSpacing = 10 * 60;
|
||||
|
@ -278,9 +271,6 @@ public:
|
|||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = Consensus::BIP9Deployment::ALWAYS_ACTIVE;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
|
||||
|
||||
// The best chain should have at least this much work.
|
||||
consensus.nMinimumChainWork = uint256S("0x00");
|
||||
|
@ -297,7 +287,7 @@ public:
|
|||
m_assumed_blockchain_size = 0;
|
||||
m_assumed_chain_state_size = 0;
|
||||
|
||||
UpdateVersionBitsParametersFromArgs(args);
|
||||
UpdateActivationParametersFromArgs(args);
|
||||
|
||||
genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN);
|
||||
consensus.hashGenesisBlock = genesis.GetHash();
|
||||
|
@ -340,11 +330,22 @@ public:
|
|||
consensus.vDeployments[d].nStartTime = nStartTime;
|
||||
consensus.vDeployments[d].nTimeout = nTimeout;
|
||||
}
|
||||
void UpdateVersionBitsParametersFromArgs(const ArgsManager& args);
|
||||
void UpdateActivationParametersFromArgs(const ArgsManager& args);
|
||||
};
|
||||
|
||||
void CRegTestParams::UpdateVersionBitsParametersFromArgs(const ArgsManager& args)
|
||||
void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
|
||||
{
|
||||
if (gArgs.IsArgSet("-segwitheight")) {
|
||||
int64_t height = gArgs.GetArg("-segwitheight", consensus.SegwitHeight);
|
||||
if (height < -1 || height >= std::numeric_limits<int>::max()) {
|
||||
throw std::runtime_error(strprintf("Activation height %ld for segwit is out of valid range. Use -1 to disable segwit.", height));
|
||||
} else if (height == -1) {
|
||||
LogPrintf("Segwit disabled for testing\n");
|
||||
height = std::numeric_limits<int>::max();
|
||||
}
|
||||
consensus.SegwitHeight = static_cast<int>(height);
|
||||
}
|
||||
|
||||
if (!args.IsArgSet("-vbparams")) return;
|
||||
|
||||
for (const std::string& strDeployment : args.GetArgs("-vbparams")) {
|
||||
|
|
|
@ -19,6 +19,7 @@ void SetupChainParamsBaseOptions()
|
|||
{
|
||||
gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
|
||||
"This is intended for regression testing tools and app development.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
|
||||
gArgs.AddArg("-segwitheight=<n>", "Set the activation height of segwit. -1 to disable. (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
gArgs.AddArg("-testnet", "Use the test chain", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ namespace Consensus {
|
|||
enum DeploymentPos
|
||||
{
|
||||
DEPLOYMENT_TESTDUMMY,
|
||||
DEPLOYMENT_SEGWIT, // Deployment of BIP141, BIP143, and BIP147.
|
||||
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp
|
||||
MAX_VERSION_BITS_DEPLOYMENTS
|
||||
};
|
||||
|
@ -59,6 +58,10 @@ struct Params {
|
|||
int BIP66Height;
|
||||
/** Block height at which CSV (BIP68, BIP112 and BIP113) becomes active */
|
||||
int CSVHeight;
|
||||
/** Block height at which Segwit (BIP141, BIP143 and BIP147) becomes active.
|
||||
* Note that segwit v0 script rules are enforced on all blocks except the
|
||||
* BIP 16 exception blocks. */
|
||||
int SegwitHeight;
|
||||
/**
|
||||
* Minimum blocks including miner confirmation of the total of 2016 blocks in a retargeting period,
|
||||
* (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments.
|
||||
|
|
|
@ -1670,12 +1670,9 @@ bool AppInitMain(InitInterfaces& interfaces)
|
|||
}
|
||||
}
|
||||
|
||||
if (chainparams.GetConsensus().vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0) {
|
||||
// Only advertise witness capabilities if they have a reasonable start time.
|
||||
// This allows us to have the code merged without a defined softfork, by setting its
|
||||
// end time to 0.
|
||||
// Note that setting NODE_WITNESS is never required: the only downside from not
|
||||
// doing so is that after activation, no upgraded nodes will fetch from you.
|
||||
if (chainparams.GetConsensus().SegwitHeight != std::numeric_limits<int>::max()) {
|
||||
// Advertise witness capabilities.
|
||||
// The option to not set NODE_WITNESS is only used in the tests and should be removed.
|
||||
nLocalServices = ServiceFlags(nLocalServices | NODE_WITNESS);
|
||||
}
|
||||
|
||||
|
|
|
@ -1338,7 +1338,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
|
|||
BuriedForkDescPushBack(softforks, "bip66", consensusParams.BIP66Height);
|
||||
BuriedForkDescPushBack(softforks, "bip65", consensusParams.BIP65Height);
|
||||
BuriedForkDescPushBack(softforks, "csv", consensusParams.CSVHeight);
|
||||
BIP9SoftForkDescPushBack(softforks, "segwit", consensusParams, Consensus::DEPLOYMENT_SEGWIT);
|
||||
BuriedForkDescPushBack(softforks, "segwit", consensusParams.SegwitHeight);
|
||||
BIP9SoftForkDescPushBack(softforks, "testdummy", consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
|
||||
obj.pushKV("softforks", softforks);
|
||||
|
||||
|
|
|
@ -482,9 +482,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
|||
// TODO: Maybe recheck connections/IBD and (if something wrong) send an expires-immediately template to stop miners?
|
||||
}
|
||||
|
||||
const struct VBDeploymentInfo& segwit_info = VersionBitsDeploymentInfo[Consensus::DEPLOYMENT_SEGWIT];
|
||||
// GBT must be called with 'segwit' set in the rules
|
||||
if (setClientRules.count(segwit_info.name) != 1) {
|
||||
if (setClientRules.count("segwit") != 1) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the segwit rule set (call with {\"rules\": [\"segwit\"]})");
|
||||
}
|
||||
|
||||
|
@ -521,7 +520,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
|||
pblock->nNonce = 0;
|
||||
|
||||
// NOTE: If at some point we support pre-segwit miners post-segwit-activation, this needs to take segwit support into consideration
|
||||
const bool fPreSegWit = (ThresholdState::ACTIVE != VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache));
|
||||
const bool fPreSegWit = (pindexPrev->nHeight + 1 < consensusParams.SegwitHeight);
|
||||
|
||||
UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ TestChain100Setup::TestChain100Setup() : TestingSetup(CBaseChainParams::REGTEST)
|
|||
{
|
||||
// CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests.
|
||||
// TODO: fix the code to support SegWit blocks.
|
||||
gArgs.ForceSetArg("-vbparams", strprintf("segwit:0:%d", (int64_t)Consensus::BIP9Deployment::NO_TIMEOUT));
|
||||
gArgs.ForceSetArg("-segwitheight", "432");
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
|
||||
// Generate a 100-block chain:
|
||||
|
|
|
@ -1608,7 +1608,7 @@ static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS] GUARDED_BY(cs_
|
|||
// environment. See test/functional/p2p-segwit.py.
|
||||
static bool IsScriptWitnessEnabled(const Consensus::Params& params)
|
||||
{
|
||||
return params.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0;
|
||||
return params.SegwitHeight != std::numeric_limits<int>::max();
|
||||
}
|
||||
|
||||
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
|
|||
flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
|
||||
}
|
||||
|
||||
if (IsNullDummyEnabled(pindex->pprev, consensusparams)) {
|
||||
// Start enforcing BIP147 NULLDUMMY (activated simultaneously with segwit)
|
||||
if (IsWitnessEnabled(pindex->pprev, consensusparams)) {
|
||||
flags |= SCRIPT_VERIFY_NULLDUMMY;
|
||||
}
|
||||
|
||||
|
@ -3045,14 +3046,8 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
|
|||
|
||||
bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == ThresholdState::ACTIVE);
|
||||
}
|
||||
|
||||
bool IsNullDummyEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == ThresholdState::ACTIVE);
|
||||
int height = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1;
|
||||
return (height >= params.SegwitHeight);
|
||||
}
|
||||
|
||||
// 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
|
|||
std::vector<unsigned char> commitment;
|
||||
int commitpos = GetWitnessCommitmentIndex(block);
|
||||
std::vector<unsigned char> ret(32, 0x00);
|
||||
if (consensusParams.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0) {
|
||||
if (consensusParams.SegwitHeight != std::numeric_limits<int>::max()) {
|
||||
if (commitpos == -1) {
|
||||
uint256 witnessroot = BlockWitnessMerkleRoot(block, nullptr);
|
||||
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
|
|||
// {0xaa, 0x21, 0xa9, 0xed}, and the following 32 bytes are SHA256^2(witness root, witness reserved value). In case there are
|
||||
// multiple, the last one is used.
|
||||
bool fHaveWitness = false;
|
||||
if (VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == ThresholdState::ACTIVE) {
|
||||
if (nHeight >= consensusParams.SegwitHeight) {
|
||||
int commitpos = GetWitnessCommitmentIndex(block);
|
||||
if (commitpos != -1) {
|
||||
bool malleated = false;
|
||||
|
|
|
@ -383,12 +383,10 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
|
|||
/** Check a block is completely valid from start to finish (only works on top of our current best block) */
|
||||
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
/** Check whether witness commitments are required for block. */
|
||||
/** Check whether witness commitments are required for a block, and whether to enforce NULLDUMMY (BIP 147) rules.
|
||||
* Note that transaction witness validation rules are always enforced when P2SH is enforced. */
|
||||
bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
|
||||
|
||||
/** Check whether NULLDUMMY (BIP 147) has activated. */
|
||||
bool IsNullDummyEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
|
||||
|
||||
/** When there are blocks in the active chain with missing data, rewind the chainstate and remove them from the block index */
|
||||
bool RewindBlockIndex(const CChainParams& params) LOCKS_EXCLUDED(cs_main);
|
||||
|
||||
|
|
|
@ -11,8 +11,4 @@ const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_B
|
|||
/*.name =*/ "testdummy",
|
||||
/*.gbt_force =*/ true,
|
||||
},
|
||||
{
|
||||
/*.name =*/ "segwit",
|
||||
/*.gbt_force =*/ true,
|
||||
}
|
||||
};
|
||||
|
|
|
@ -41,7 +41,7 @@ class NULLDUMMYTest(BitcoinTestFramework):
|
|||
self.setup_clean_chain = True
|
||||
# This script tests NULLDUMMY activation, which is part of the 'segwit' deployment, so we go through
|
||||
# normal segwit activation here (and don't use the default always-on behaviour).
|
||||
self.extra_args = [['-whitelist=127.0.0.1', '-vbparams=segwit:0:999999999999', '-addresstype=legacy']]
|
||||
self.extra_args = [['-whitelist=127.0.0.1', '-segwitheight=432', '-addresstype=legacy']]
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_wallet()
|
||||
|
|
|
@ -55,20 +55,20 @@ class SegWitTest(BitcoinTestFramework):
|
|||
[
|
||||
"-acceptnonstdtxn=1",
|
||||
"-rpcserialversion=0",
|
||||
"-vbparams=segwit:0:999999999999",
|
||||
"-segwitheight=432",
|
||||
"-addresstype=legacy",
|
||||
],
|
||||
[
|
||||
"-acceptnonstdtxn=1",
|
||||
"-blockversion=4",
|
||||
"-rpcserialversion=1",
|
||||
"-vbparams=segwit:0:999999999999",
|
||||
"-segwitheight=432",
|
||||
"-addresstype=legacy",
|
||||
],
|
||||
[
|
||||
"-acceptnonstdtxn=1",
|
||||
"-blockversion=536870915",
|
||||
"-vbparams=segwit:0:999999999999",
|
||||
"-segwitheight=432",
|
||||
"-addresstype=legacy",
|
||||
],
|
||||
]
|
||||
|
|
|
@ -14,7 +14,7 @@ from test_framework.messages import BlockTransactions, BlockTransactionsRequest,
|
|||
from test_framework.mininode import mininode_lock, P2PInterface
|
||||
from test_framework.script import CScript, OP_TRUE, OP_DROP
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_equal, get_bip9_status, wait_until
|
||||
from test_framework.util import assert_equal, wait_until, softfork_active
|
||||
|
||||
# TestP2PConn: A peer we use to send messages to bitcoind, and store responses.
|
||||
class TestP2PConn(P2PInterface):
|
||||
|
@ -803,7 +803,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
|||
# We will need UTXOs to construct transactions in later tests.
|
||||
self.make_utxos()
|
||||
|
||||
assert_equal(get_bip9_status(self.nodes[0], "segwit")["status"], 'active')
|
||||
assert softfork_active(self.nodes[0], "segwit")
|
||||
|
||||
self.log.info("Testing SENDCMPCT p2p message... ")
|
||||
self.test_sendcmpct(self.segwit_node, old_node=self.old_node)
|
||||
|
|
|
@ -76,7 +76,7 @@ from test_framework.util import (
|
|||
assert_equal,
|
||||
connect_nodes,
|
||||
disconnect_nodes,
|
||||
get_bip9_status,
|
||||
softfork_active,
|
||||
hex_str_to_bytes,
|
||||
assert_raises_rpc_error,
|
||||
)
|
||||
|
@ -88,6 +88,8 @@ VB_TOP_BITS = 0x20000000
|
|||
|
||||
MAX_SIGOP_COST = 80000
|
||||
|
||||
SEGWIT_HEIGHT = 120
|
||||
|
||||
class UTXO():
|
||||
"""Used to keep track of anyone-can-spend outputs that we can use in the tests."""
|
||||
def __init__(self, sha256, n, value):
|
||||
|
@ -185,9 +187,9 @@ class SegWitTest(BitcoinTestFramework):
|
|||
self.num_nodes = 3
|
||||
# This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
|
||||
self.extra_args = [
|
||||
["-whitelist=127.0.0.1", "-acceptnonstdtxn=1", "-vbparams=segwit:0:999999999999"],
|
||||
["-whitelist=127.0.0.1", "-acceptnonstdtxn=0", "-vbparams=segwit:0:999999999999"],
|
||||
["-whitelist=127.0.0.1", "-acceptnonstdtxn=1", "-vbparams=segwit:0:0"],
|
||||
["-whitelist=127.0.0.1", "-acceptnonstdtxn=1", "-segwitheight={}".format(SEGWIT_HEIGHT)],
|
||||
["-whitelist=127.0.0.1", "-acceptnonstdtxn=0", "-segwitheight={}".format(SEGWIT_HEIGHT)],
|
||||
["-whitelist=127.0.0.1", "-acceptnonstdtxn=1", "-segwitheight=-1"]
|
||||
]
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
|
@ -231,26 +233,18 @@ class SegWitTest(BitcoinTestFramework):
|
|||
# Keep a place to store utxo's that can be used in later tests
|
||||
self.utxo = []
|
||||
|
||||
# Segwit status 'defined'
|
||||
self.segwit_status = 'defined'
|
||||
self.log.info("Starting tests before segwit activation")
|
||||
self.segwit_active = False
|
||||
|
||||
self.test_non_witness_transaction()
|
||||
self.test_unnecessary_witness_before_segwit_activation()
|
||||
self.test_v0_outputs_arent_spendable()
|
||||
self.test_block_relay()
|
||||
self.advance_to_segwit_started()
|
||||
|
||||
# Segwit status 'started'
|
||||
|
||||
self.test_getblocktemplate_before_lockin()
|
||||
self.advance_to_segwit_lockin()
|
||||
|
||||
# Segwit status 'locked_in'
|
||||
|
||||
self.test_unnecessary_witness_before_segwit_activation()
|
||||
self.test_witness_tx_relay_before_segwit_activation()
|
||||
self.test_block_relay()
|
||||
self.test_standardness_v0()
|
||||
|
||||
self.log.info("Advancing to segwit activation")
|
||||
self.advance_to_segwit_active()
|
||||
|
||||
# Segwit status 'active'
|
||||
|
@ -282,15 +276,15 @@ class SegWitTest(BitcoinTestFramework):
|
|||
def subtest(func): # noqa: N805
|
||||
"""Wraps the subtests for logging and state assertions."""
|
||||
def func_wrapper(self, *args, **kwargs):
|
||||
self.log.info("Subtest: {} (Segwit status = {})".format(func.__name__, self.segwit_status))
|
||||
self.log.info("Subtest: {} (Segwit active = {})".format(func.__name__, self.segwit_active))
|
||||
# Assert segwit status is as expected
|
||||
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], self.segwit_status)
|
||||
assert_equal(softfork_active(self.nodes[0], 'segwit'), self.segwit_active)
|
||||
func(self, *args, **kwargs)
|
||||
# Each subtest should leave some utxos for the next subtest
|
||||
assert self.utxo
|
||||
self.sync_blocks()
|
||||
# Assert segwit status is as expected at end of subtest
|
||||
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], self.segwit_status)
|
||||
assert_equal(softfork_active(self.nodes[0], 'segwit'), self.segwit_active)
|
||||
|
||||
return func_wrapper
|
||||
|
||||
|
@ -392,7 +386,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||
|
||||
# Check that we can getdata for witness blocks or regular blocks,
|
||||
# and the right thing happens.
|
||||
if self.segwit_status != 'active':
|
||||
if not self.segwit_active:
|
||||
# Before activation, we should be able to request old blocks with
|
||||
# or without witness, and they should be the same.
|
||||
chain_height = self.nodes[0].getblockcount()
|
||||
|
@ -535,33 +529,19 @@ class SegWitTest(BitcoinTestFramework):
|
|||
self.utxo.pop(0)
|
||||
self.utxo.append(UTXO(txid, 2, value))
|
||||
|
||||
@subtest
|
||||
def advance_to_segwit_started(self):
|
||||
"""Mine enough blocks for segwit's vb state to be 'started'."""
|
||||
height = self.nodes[0].getblockcount()
|
||||
# Will need to rewrite the tests here if we are past the first period
|
||||
assert height < VB_PERIOD - 1
|
||||
# Advance to end of period, status should now be 'started'
|
||||
self.nodes[0].generate(VB_PERIOD - height - 1)
|
||||
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'started')
|
||||
self.segwit_status = 'started'
|
||||
|
||||
@subtest
|
||||
def test_getblocktemplate_before_lockin(self):
|
||||
txid = int(self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1), 16)
|
||||
|
||||
for node in [self.nodes[0], self.nodes[2]]:
|
||||
gbt_results = node.getblocktemplate({"rules": ["segwit"]})
|
||||
block_version = gbt_results['version']
|
||||
if node == self.nodes[2]:
|
||||
# If this is a non-segwit node, we should not get a witness
|
||||
# commitment, nor a version bit signalling segwit.
|
||||
assert_equal(block_version & (1 << VB_WITNESS_BIT), 0)
|
||||
# commitment.
|
||||
assert 'default_witness_commitment' not in gbt_results
|
||||
else:
|
||||
# For segwit-aware nodes, check the version bit and the witness
|
||||
# commitment are correct.
|
||||
assert block_version & (1 << VB_WITNESS_BIT) != 0
|
||||
# For segwit-aware nodes, check the witness
|
||||
# commitment is correct.
|
||||
assert 'default_witness_commitment' in gbt_results
|
||||
witness_commitment = gbt_results['default_witness_commitment']
|
||||
|
||||
|
@ -571,18 +551,9 @@ class SegWitTest(BitcoinTestFramework):
|
|||
script = get_witness_script(witness_root, 0)
|
||||
assert_equal(witness_commitment, script.hex())
|
||||
|
||||
@subtest
|
||||
def advance_to_segwit_lockin(self):
|
||||
"""Mine enough blocks to lock in segwit, but don't activate."""
|
||||
height = self.nodes[0].getblockcount()
|
||||
# Advance to end of period, and verify lock-in happens at the end
|
||||
self.nodes[0].generate(VB_PERIOD - 1)
|
||||
height = self.nodes[0].getblockcount()
|
||||
assert (height % VB_PERIOD) == VB_PERIOD - 2
|
||||
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'started')
|
||||
# Clear out the mempool
|
||||
self.nodes[0].generate(1)
|
||||
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'locked_in')
|
||||
self.segwit_status = 'locked_in'
|
||||
self.sync_blocks()
|
||||
|
||||
@subtest
|
||||
def test_witness_tx_relay_before_segwit_activation(self):
|
||||
|
@ -686,7 +657,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||
tx3.wit.vtxinwit.append(CTxInWitness())
|
||||
tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_program]
|
||||
tx3.rehash()
|
||||
if self.segwit_status != 'active':
|
||||
if not self.segwit_active:
|
||||
# Just check mempool acceptance, but don't add the transaction to the mempool, since witness is disallowed
|
||||
# in blocks and the tx is impossible to mine right now.
|
||||
assert_equal(self.nodes[0].testmempoolaccept([tx3.serialize_with_witness().hex()]), [{'txid': tx3.hash, 'allowed': True}])
|
||||
|
@ -707,12 +678,13 @@ class SegWitTest(BitcoinTestFramework):
|
|||
@subtest
|
||||
def advance_to_segwit_active(self):
|
||||
"""Mine enough blocks to activate segwit."""
|
||||
assert not softfork_active(self.nodes[0], 'segwit')
|
||||
height = self.nodes[0].getblockcount()
|
||||
self.nodes[0].generate(VB_PERIOD - (height % VB_PERIOD) - 2)
|
||||
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'locked_in')
|
||||
self.nodes[0].generate(SEGWIT_HEIGHT - height - 2)
|
||||
assert not softfork_active(self.nodes[0], 'segwit')
|
||||
self.nodes[0].generate(1)
|
||||
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'active')
|
||||
self.segwit_status = 'active'
|
||||
assert softfork_active(self.nodes[0], 'segwit')
|
||||
self.segwit_active = True
|
||||
|
||||
@subtest
|
||||
def test_p2sh_witness(self):
|
||||
|
@ -1924,13 +1896,13 @@ class SegWitTest(BitcoinTestFramework):
|
|||
|
||||
# Restart with the new binary
|
||||
self.stop_node(2)
|
||||
self.start_node(2, extra_args=["-vbparams=segwit:0:999999999999"])
|
||||
self.start_node(2, extra_args=["-segwitheight={}".format(SEGWIT_HEIGHT)])
|
||||
connect_nodes(self.nodes[0], 2)
|
||||
|
||||
self.sync_blocks()
|
||||
|
||||
# Make sure that this peer thinks segwit has activated.
|
||||
assert get_bip9_status(self.nodes[2], 'segwit')['status'] == "active"
|
||||
assert softfork_active(self.nodes[2], 'segwit')
|
||||
|
||||
# Make sure this peer's blocks match those of node0.
|
||||
height = self.nodes[2].getblockcount()
|
||||
|
|
|
@ -342,10 +342,6 @@ def delete_cookie_file(datadir):
|
|||
logger.debug("Deleting leftover cookie file")
|
||||
os.remove(os.path.join(datadir, "regtest", ".cookie"))
|
||||
|
||||
def get_bip9_status(node, key):
|
||||
info = node.getblockchaininfo()
|
||||
return info['softforks'][key]['bip9']
|
||||
|
||||
def softfork_active(node, key):
|
||||
"""Return whether a softfork is active."""
|
||||
return node.getblockchaininfo()['softforks'][key]['active']
|
||||
|
|
Loading…
Reference in a new issue