diff --git a/src/chainparams.cpp b/src/chainparams.cpp --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -128,8 +128,8 @@ // November 13, 2017 hard fork consensus.daaHeight = 504031; - // Nov 15, 2018 hard fork - consensus.magneticAnomalyActivationTime = 1542300000; + // November 15, 2018 hard fork + consensus.magneticAnomalyHeight = 556767; // Wed, 15 May 2019 12:00:00 UTC hard fork consensus.greatWallActivationTime = 1557921600; @@ -299,8 +299,8 @@ // November 13, 2017 hard fork consensus.daaHeight = 1188697; - // Nov 15, 2018 hard fork - consensus.magneticAnomalyActivationTime = 1542300000; + // November 15, 2018 hard fork + consensus.magneticAnomalyHeight = 1254249; // Wed, 15 May 2019 12:00:00 UTC hard fork consensus.greatWallActivationTime = 1557921600; @@ -419,8 +419,8 @@ // November 13, 2017 hard fork is always on on regtest. consensus.daaHeight = 0; - // Nov 15, 2018 hard fork - consensus.magneticAnomalyActivationTime = 1542300000; + // November 15, 2018 hard fork is always on on regtest. + consensus.magneticAnomalyHeight = 0; // Wed, 15 May 2019 12:00:00 UTC hard fork consensus.greatWallActivationTime = 1557921600; diff --git a/src/consensus/activation.h b/src/consensus/activation.h --- a/src/consensus/activation.h +++ b/src/consensus/activation.h @@ -16,13 +16,10 @@ /** Check if DAA HF has activated. */ bool IsDAAEnabled(const Config &config, const CBlockIndex *pindexPrev); -/** Check if Nov 15, 2018 HF has activated. */ +/** Check if Nov 15, 2018 HF has activated using block height. */ +bool IsMagneticAnomalyEnabled(const Config &config, int nHeight); +/** Check if Nov 15, 2018 HF has activated using previous block index. */ bool IsMagneticAnomalyEnabled(const Config &config, const CBlockIndex *pindexPrev); -/** - * Also check if Nov 15, 2018 HF has activated, but with an API that isn't as - * safe. - */ -bool IsMagneticAnomalyEnabled(const Config &config, int64_t nMedianTimePast); #endif // BITCOIN_CONSENSUS_ACTIVATION_H diff --git a/src/consensus/activation.cpp b/src/consensus/activation.cpp --- a/src/consensus/activation.cpp +++ b/src/consensus/activation.cpp @@ -33,11 +33,9 @@ return IsDAAEnabled(config, pindexPrev->nHeight); } -bool IsMagneticAnomalyEnabled(const Config &config, int64_t nMedianTimePast) { - return nMedianTimePast >= gArgs.GetArg("-magneticanomalyactivationtime", - config.GetChainParams() - .GetConsensus() - .magneticAnomalyActivationTime); +bool IsMagneticAnomalyEnabled(const Config &config, int nHeight) { + return nHeight >= + config.GetChainParams().GetConsensus().magneticAnomalyHeight; } bool IsMagneticAnomalyEnabled(const Config &config, @@ -46,5 +44,5 @@ return false; } - return IsMagneticAnomalyEnabled(config, pindexPrev->GetMedianTimePast()); + return IsMagneticAnomalyEnabled(config, pindexPrev->nHeight); } diff --git a/src/consensus/params.h b/src/consensus/params.h --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -54,8 +54,8 @@ int uahfHeight; /** Block height at which the new DAA becomes active */ int daaHeight; - /** Unix time used for MTP activation of Nov 15 2018, hardfork */ - int magneticAnomalyActivationTime; + /** Block height at which the magnetic anomaly activation becomes active */ + int magneticAnomalyHeight; /** Unix time used for MTP activation of 15 May 2019 12:00:00 UTC upgrade */ int greatWallActivationTime; /** diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp --- a/src/consensus/tx_verify.cpp +++ b/src/consensus/tx_verify.cpp @@ -46,7 +46,7 @@ "non-final transaction"); } - if (IsMagneticAnomalyEnabled(config, nMedianTimePast)) { + if (IsMagneticAnomalyEnabled(config, nHeight)) { // Size limit if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) < MIN_TX_SIZE) { diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -773,23 +773,6 @@ BOOST_CHECK(!IsStandardTx(CTransaction(t), reason)); } -BOOST_AUTO_TEST_CASE(txsize_activation_test) { - const Config &config = GetConfig(); - const int64_t magneticAnomalyActivationTime = - config.GetChainParams().GetConsensus().magneticAnomalyActivationTime; - - // A minimaly sized transction. - CTransaction minTx; - CValidationState state; - - BOOST_CHECK(ContextualCheckTransaction(config, minTx, state, 1234, 5678, - magneticAnomalyActivationTime - 1)); - BOOST_CHECK(!ContextualCheckTransaction(config, minTx, state, 1234, 5678, - magneticAnomalyActivationTime)); - BOOST_CHECK_EQUAL(state.GetRejectCode(), REJECT_INVALID); - BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txns-undersize"); -} - BOOST_AUTO_TEST_CASE(tx_transaction_fee) { std::vector sizes = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; for (size_t inputs : sizes) { diff --git a/test/functional/abc-checkdatasig-activation.py b/test/functional/abc-checkdatasig-activation.py deleted file mode 100755 --- a/test/functional/abc-checkdatasig-activation.py +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2018 The Bitcoin developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. -""" -This test checks activation of OP_CHECKDATASIG -""" - -from test_framework.test_framework import ComparisonTestFramework -from test_framework.util import satoshi_round, assert_equal, assert_raises_rpc_error -from test_framework.comptool import TestManager, TestInstance, RejectResult -from test_framework.blocktools import * -from test_framework.script import * - -# far into the future -MAGNETIC_ANOMALY_START_TIME = 2000000000 - -# Error due to invalid opcodes -BAD_OPCODE_ERROR = b'mandatory-script-verify-flag-failed (Opcode missing or not understood)' -RPC_BAD_OPCODE_ERROR = "16: " + \ - BAD_OPCODE_ERROR.decode("utf-8") - - -class PreviousSpendableOutput(): - - def __init__(self, tx=CTransaction(), n=-1): - self.tx = tx - self.n = n # the output we're spending - - -class CheckDataSigActivationTest(ComparisonTestFramework): - - def set_test_params(self): - self.num_nodes = 1 - self.setup_clean_chain = True - self.extra_args = [['-whitelist=127.0.0.1', - "-magneticanomalyactivationtime=%d" % MAGNETIC_ANOMALY_START_TIME, - "-replayprotectionactivationtime=%d" % (2 * MAGNETIC_ANOMALY_START_TIME)]] - - def create_checkdatasig_tx(self, count): - node = self.nodes[0] - utxos = node.listunspent() - assert(len(utxos) > 0) - utxo = utxos[0] - tx = CTransaction() - value = int(satoshi_round(utxo["amount"]) * COIN) // count - tx.vin = [CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]))] - tx.vout = [] - signature = bytearray.fromhex( - '30440220256c12175e809381f97637933ed6ab97737d263eaaebca6add21bced67fd12a402205ce29ecc1369d6fc1b51977ed38faaf41119e3be1d7edfafd7cfaf0b6061bd07') - message = bytearray.fromhex('') - pubkey = bytearray.fromhex( - '038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508') - for _ in range(count): - tx.vout.append(CTxOut(value, CScript( - [signature, message, pubkey, OP_CHECKDATASIG]))) - tx.vout[0].nValue -= node.calculate_fee(tx) - tx_signed = node.signrawtransaction(ToHex(tx))["hex"] - return tx_signed - - def run_test(self): - self.test = TestManager(self, self.options.tmpdir) - self.test.add_all_connections(self.nodes) - # Start up network handling in another thread - NetworkThread().start() - self.test.run() - - def get_tests(self): - node = self.nodes[0] - - # First, we generate some coins to spend. - node.generate(125) - - # Create various outputs using the OP_CHECKDATASIG - # to check for activation. - tx_hex = self.create_checkdatasig_tx(25) - txid = node.sendrawtransaction(tx_hex) - assert(txid in set(node.getrawmempool())) - - node.generate(1) - assert(txid not in set(node.getrawmempool())) - - # register the spendable outputs. - tx = FromHex(CTransaction(), tx_hex) - tx.rehash() - spendable_checkdatasigs = [PreviousSpendableOutput(tx, i) - for i in range(len(tx.vout))] - - def spend_checkdatasig(): - outpoint = spendable_checkdatasigs.pop() - out = outpoint.tx.vout[outpoint.n] - tx = CTransaction() - tx.vin = [CTxIn(COutPoint(outpoint.tx.sha256, outpoint.n))] - tx.vout = [CTxOut(out.nValue, CScript([])), - CTxOut(0, CScript([random.getrandbits(800), OP_RETURN]))] - tx.vout[0].nValue -= node.calculate_fee(tx) - tx.rehash() - return tx - - # Check that transactions using checkdatasig are not accepted yet. - self.log.info("Try to use the checkdatasig opcodes before activation") - - tx0 = spend_checkdatasig() - tx0_hex = ToHex(tx0) - assert_raises_rpc_error(-26, RPC_BAD_OPCODE_ERROR, - node.sendrawtransaction, tx0_hex) - - # Push MTP forward just before activation. - self.log.info("Pushing MTP just before the activation and check again") - node.setmocktime(MAGNETIC_ANOMALY_START_TIME) - - # returns a test case that asserts that the current tip was accepted - def accepted(tip): - return TestInstance([[tip, True]]) - - # returns a test case that asserts that the current tip was rejected - def rejected(tip, reject=None): - if reject is None: - return TestInstance([[tip, False]]) - else: - return TestInstance([[tip, reject]]) - - def next_block(block_time): - # get block height - blockchaininfo = node.getblockchaininfo() - height = int(blockchaininfo['blocks']) - - # create the block - coinbase = create_coinbase(height) - coinbase.rehash() - block = create_block( - int(node.getbestblockhash(), 16), coinbase, block_time) - - # Do PoW, which is cheap on regnet - block.solve() - return block - - for i in range(6): - b = next_block(MAGNETIC_ANOMALY_START_TIME + i - 1) - yield accepted(b) - - # Check again just before the activation time - assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], - MAGNETIC_ANOMALY_START_TIME - 1) - assert_raises_rpc_error(-26, RPC_BAD_OPCODE_ERROR, - node.sendrawtransaction, tx0_hex) - - def add_tx(block, tx): - block.vtx.append(tx) - block.hashMerkleRoot = block.calc_merkle_root() - block.solve() - - b = next_block(MAGNETIC_ANOMALY_START_TIME + 6) - add_tx(b, tx0) - yield rejected(b, RejectResult(16, b'blk-bad-inputs')) - - self.log.info("Activates checkdatasig") - fork_block = next_block(MAGNETIC_ANOMALY_START_TIME + 6) - yield accepted(fork_block) - - assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], - MAGNETIC_ANOMALY_START_TIME) - - tx0id = node.sendrawtransaction(tx0_hex) - assert(tx0id in set(node.getrawmempool())) - - # Transactions can also be included in blocks. - magneticanomalyblock = next_block(MAGNETIC_ANOMALY_START_TIME + 7) - add_tx(magneticanomalyblock, tx0) - yield accepted(magneticanomalyblock) - - -if __name__ == '__main__': - CheckDataSigActivationTest().main() diff --git a/test/functional/abc-magnetic-anomaly-activation.py b/test/functional/abc-magnetic-anomaly-activation.py deleted file mode 100755 --- a/test/functional/abc-magnetic-anomaly-activation.py +++ /dev/null @@ -1,277 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2018 The Bitcoin developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. -""" -This test checks that simple features of the magnetic anomaly fork -activates properly. More complex features are given their own tests. -""" - -from test_framework.test_framework import ComparisonTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error -from test_framework.comptool import TestManager, TestInstance, RejectResult -from test_framework.blocktools import create_coinbase, create_block -from test_framework.mininode import * -from test_framework.script import * -from test_framework.cdefs import MIN_TX_SIZE -from collections import deque - -# far into the future -MAGNETIC_ANOMALY_START_TIME = 2000000000 -RPC_VERIFY_REJECTED = -26 - - -class PreviousSpendableOutput(): - - def __init__(self, tx=CTransaction(), n=-1): - self.tx = tx - self.n = n # the output we're spending - - -class MagneticAnomalyActivationTest(ComparisonTestFramework): - - def set_test_params(self): - self.num_nodes = 1 - self.setup_clean_chain = True - self.block_heights = {} - self.tip = None - self.blocks = {} - self.extra_args = [['-whitelist=127.0.0.1', - "-magneticanomalyactivationtime=%d" % MAGNETIC_ANOMALY_START_TIME, - "-replayprotectionactivationtime=%d" % (2 * MAGNETIC_ANOMALY_START_TIME)]] - - def run_test(self): - self.test = TestManager(self, self.options.tmpdir) - self.test.add_all_connections(self.nodes) - # Start up network handling in another thread - NetworkThread().start() - # Set the blocksize to 2MB as initial condition - self.nodes[0].setmocktime(MAGNETIC_ANOMALY_START_TIME) - self.test.run() - - def add_transactions_to_block(self, block, tx_list): - [tx.rehash() for tx in tx_list] - block.vtx.extend(tx_list) - - def new_transaction(self, spend, tx_size=0, pushonly=True, cleanstack=True): - tx = CTransaction() - # Make sure we have plenty enough to spend going forward. - spendable_outputs = deque([spend]) - - # Spend from one of the spendable outputs - spend = spendable_outputs.popleft() - tx.vin.append(CTxIn(COutPoint(spend.tx.sha256, spend.n))) - extra_ops = [] - if pushonly == False: - extra_ops += [OP_TRUE, OP_DROP] - if cleanstack == False: - extra_ops += [OP_TRUE] - tx.vin[0].scriptSig = CScript(extra_ops) - - # Add spendable outputs - for i in range(2): - tx.vout.append(CTxOut(0, CScript([OP_TRUE]))) - spendable_outputs.append(PreviousSpendableOutput(tx, i)) - - # Put some random data into the transaction in order to randomize ids. - if tx_size == 0: - tx.vout.append( - CTxOut(0, CScript([random.getrandbits(8), OP_RETURN]))) - else: - # Create an input to pad the transaction. - tx.vout.append(CTxOut(0, CScript([OP_RETURN]))) - - # Estimate the size of the padding. - push_size = tx_size - len(tx.serialize()) - 1 - - # Because several field are of variable size, we grow the push slowly - # up to the requested size. - while len(tx.serialize()) < tx_size: - # Ensure the padding has a left most bit on, so it's - # exactly the correct number of bits. - padding = random.randrange( - 1 << 8 * push_size - 2, 1 << 8 * push_size - 1) - tx.vout[2] = CTxOut(0, CScript([padding, OP_RETURN])) - push_size += 1 - - assert_equal(len(tx.serialize()), tx_size) - - tx.rehash() - return tx - - def next_block(self, number, spend_tx=None): - if self.tip == None: - base_block_hash = self.genesis_hash - import time - block_time = int(time.time()) + 1 - else: - base_block_hash = self.tip.sha256 - block_time = self.tip.nTime + 1 - # First create the coinbase - height = self.block_heights[base_block_hash] + 1 - coinbase = create_coinbase(height) - coinbase.rehash() - if spend_tx == None: - # We need to have something to spend to fill the block. - block = create_block(base_block_hash, coinbase, block_time) - else: - # All but one satoshi to fees - #coinbase.vout[0].nValue += spend.tx.vout[spend.n].nValue - 1 - coinbase.vout[0].nValue += spend_tx.vin[0].prevout.n - 1 - coinbase.rehash() - block = create_block(base_block_hash, coinbase, block_time) - - # Add the transaction to the block - self.add_transactions_to_block(block, [spend_tx]) - - # Now that we added a bunch of transactions, we need to recompute - # the merkle root. - block.hashMerkleRoot = block.calc_merkle_root() - - # Do PoW, which is cheap on regnet - block.solve() - self.tip = block - self.block_heights[block.sha256] = height - assert number not in self.blocks - self.blocks[number] = block - return block - - def get_tests(self): - node = self.nodes[0] - self.genesis_hash = int(node.getbestblockhash(), 16) - self.block_heights[self.genesis_hash] = 0 - spendable_outputs = [] - - # save the current tip so it can be spent by a later block - def save_spendable_output(): - spendable_outputs.append(self.tip) - - # get an output that we previously marked as spendable - def get_spendable_output(): - return PreviousSpendableOutput(spendable_outputs.pop(0).vtx[0], 0) - - # returns a test case that asserts that the current tip was accepted - def accepted(): - return TestInstance([[self.tip, True]]) - - # returns a test case that asserts that the current tip was rejected - def rejected(reject=None): - if reject is None: - return TestInstance([[self.tip, False]]) - else: - return TestInstance([[self.tip, reject]]) - - # move the tip back to a previous block - def tip(number): - self.tip = self.blocks[number] - - # adds transactions to the block and updates state - def update_block(block_number, new_transactions=[]): - block = self.blocks[block_number] - self.add_transactions_to_block(block, new_transactions) - old_sha256 = block.sha256 - block.hashMerkleRoot = block.calc_merkle_root() - block.solve() - # Update the internal state just like in next_block - self.tip = block - if block.sha256 != old_sha256: - self.block_heights[block.sha256] = self.block_heights[old_sha256] - del self.block_heights[old_sha256] - self.blocks[block_number] = block - return block - - # shorthand for functions - block = self.next_block - transaction = self.new_transaction - - # Create a new block - block(0) - save_spendable_output() - yield accepted() - - # Now we need that block to mature so we can spend the coinbase. - test = TestInstance(sync_every_block=False) - for i in range(99): - block(5000 + i) - test.blocks_and_transactions.append([self.tip, True]) - save_spendable_output() - yield test - - # collect spendable outputs now to avoid cluttering the code later on - out = [] - for i in range(100): - out.append(get_spendable_output()) - - # Let's build some blocks and test them. - for i in range(15): - n = i + 1 - block(n) - yield accepted() - - # Start moving MTP forward - bfork = block(5555) - bfork.nTime = MAGNETIC_ANOMALY_START_TIME - 1 - update_block(5555) - yield accepted() - - # Get to one block of the Nov 15, 2018 HF activation - for i in range(5): - block(5100 + i) - test.blocks_and_transactions.append([self.tip, True]) - yield test - - # Check that the MTP is just before the configured fork point. - assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], - MAGNETIC_ANOMALY_START_TIME - 1) - - # Check that block with small transactions, non push only signatures and - # non clean stack are still accepted. - small_tx_block = block(4444, - transaction(out[0], MIN_TX_SIZE - 1, pushonly=False, cleanstack=False)) - assert_equal(len(small_tx_block.vtx[1].serialize()), MIN_TX_SIZE - 1) - yield accepted() - - # Now MTP is exactly the fork time. Small transaction are now rejected. - assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], - MAGNETIC_ANOMALY_START_TIME) - - # Now that the for activated, it is not possible to have - # small transactions anymore. - small_tx_block = block(4445, transaction(out[1], MIN_TX_SIZE - 1)) - assert_equal(len(small_tx_block.vtx[1].serialize()), MIN_TX_SIZE - 1) - yield rejected(RejectResult(16, b'bad-txns-undersize')) - - # Rewind bad block. - tip(4444) - - # Now that the for activated, it is not possible to have - # non push only transactions. - non_pushonly_tx_block = block(4446, - transaction(out[1], MIN_TX_SIZE, pushonly=False)) - yield rejected(RejectResult(16, b'blk-bad-inputs')) - - # Rewind bad block. - tip(4444) - - # Now that the for activated, it is not possible to have - # non clean stack transactions. - non_cleanstack_tx_block = block(4447, - transaction(out[1], MIN_TX_SIZE, cleanstack=False)) - yield rejected(RejectResult(16, b'blk-bad-inputs')) - - # Rewind bad block. - tip(4444) - - # Verfiy that ATMP doesn't accept undersize transactions - undersized_tx = transaction(out[1], MIN_TX_SIZE - 1) - assert_raises_rpc_error(RPC_VERIFY_REJECTED, "bad-txns-undersize", - node.sendrawtransaction, ToHex(undersized_tx), True) - - # But large transactions are still ok. - large_tx_block = block(3333, transaction(out[1], MIN_TX_SIZE)) - assert_equal(len(large_tx_block.vtx[1].serialize()), MIN_TX_SIZE) - yield accepted() - - -if __name__ == '__main__': - MagneticAnomalyActivationTest().main() diff --git a/test/functional/abc-magnetic-anomaly-mining.py b/test/functional/abc-magnetic-anomaly-mining.py --- a/test/functional/abc-magnetic-anomaly-mining.py +++ b/test/functional/abc-magnetic-anomaly-mining.py @@ -28,7 +28,6 @@ self.mocktime = int(time.time()) - 600 * 100 extra_arg = ['-spendzeroconfchange=0', '-whitelist=127.0.0.1', - "-magneticanomalyactivationtime=%d" % self.mocktime, "-replayprotectionactivationtime=%d" % (10 * self.mocktime)] self.extra_args = [extra_arg, extra_arg] diff --git a/test/functional/abc-replay-protection.py b/test/functional/abc-replay-protection.py --- a/test/functional/abc-replay-protection.py +++ b/test/functional/abc-replay-protection.py @@ -19,7 +19,6 @@ # far into the future REPLAY_PROTECTION_START_TIME = 2000000000 -MAGNETIC_ANOMALY_START_TIME = 4000000000 # Error due to invalid signature INVALID_SIGNATURE_ERROR = b'mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)' @@ -43,7 +42,6 @@ self.tip = None self.blocks = {} self.extra_args = [['-whitelist=127.0.0.1', - "-magneticanomalyactivationtime=%d" % MAGNETIC_ANOMALY_START_TIME, "-replayprotectionactivationtime=%d" % REPLAY_PROTECTION_START_TIME]] def run_test(self): @@ -109,6 +107,7 @@ block = self.blocks[block_number] block.vtx.extend(new_transactions) old_sha256 = block.sha256 + make_conform_to_ctor(block) block.hashMerkleRoot = block.calc_merkle_root() block.solve() # Update the internal state just like in next_block diff --git a/test/functional/abc-transaction-ordering.py b/test/functional/abc-transaction-ordering.py --- a/test/functional/abc-transaction-ordering.py +++ b/test/functional/abc-transaction-ordering.py @@ -17,7 +17,7 @@ from collections import deque # far into the future -MAGNETIC_ANOMALY_START_TIME = 2000000000 +REPLAY_PROTECTION_START_TIME = 4000000000 class PreviousSpendableOutput(): @@ -41,8 +41,7 @@ self.blocks = {} self.extra_args = [['-whitelist=127.0.0.1', '-relaypriority=0', - "-magneticanomalyactivationtime=%d" % MAGNETIC_ANOMALY_START_TIME, - "-replayprotectionactivationtime=%d" % (2 * MAGNETIC_ANOMALY_START_TIME)]] + "-replayprotectionactivationtime={}".format(REPLAY_PROTECTION_START_TIME)]] def run_test(self): self.test = TestManager(self, self.options.tmpdir) @@ -50,7 +49,6 @@ # Start up network handling in another thread NetworkThread().start() # Set the blocksize to 2MB as initial condition - self.nodes[0].setmocktime(MAGNETIC_ANOMALY_START_TIME) self.test.run() def add_transactions_to_block(self, block, tx_list): @@ -197,30 +195,14 @@ block(n) yield accepted() - # Start moving MTP forward - bfork = block(5555) - bfork.nTime = MAGNETIC_ANOMALY_START_TIME - 1 - update_block(5555) - yield accepted() - - # Get to one block of the Nov 15, 2018 HF activation - for i in range(5): + for i in range(6): block(5100 + i) test.blocks_and_transactions.append([self.tip, True]) yield test - # Check that the MTP is just before the configured fork point. - assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], - MAGNETIC_ANOMALY_START_TIME - 1) - - # Activate the Nov 15, 2018 HF - block(5556, out[16], tx_count=16) + block(5556) yield accepted() - # Now MTP is exactly the fork time. Transactions are expected to be ordered now. - assert_equal(node.getblockheader(node.getbestblockhash())['mediantime'], - MAGNETIC_ANOMALY_START_TIME) - # Block with regular ordering are now rejected. block(5557, out[17], tx_count=16) yield rejected(RejectResult(16, b'tx-ordering')) @@ -231,7 +213,7 @@ # After we activate the Nov 15, 2018 HF, transaction order is enforced. def ordered_block(block_number, spend): b = block(block_number, spend=spend, tx_count=16) - b.vtx = [b.vtx[0]] + sorted(b.vtx[1:], key=lambda tx: tx.get_id()) + make_conform_to_ctor(b) update_block(block_number) return b @@ -239,26 +221,6 @@ ordered_block(4445, out[17]) yield accepted() - # Invalidate the best block and make sure we are back at the fork point. - ctorblockhash = node.getbestblockhash() - node.invalidateblock(ctorblockhash) - forkblockhash = node.getbestblockhash() - assert(forkblockhash != ctorblockhash) - assert_equal(node.getblockheader(forkblockhash)[ - 'mediantime'], MAGNETIC_ANOMALY_START_TIME) - - assert_equal(len(node.getrawmempool()), 15) - node.generate(1) - generatedblockhash = node.getbestblockhash() - assert(forkblockhash != generatedblockhash) - - # Reconstruct tip. - tip_hash = node.getbestblockhash() - self.tip = CBlock() - self.tip.sha256 = int(tip_hash, 16) - self.tip.nTime = timestamp = node.getblock(tip_hash)['time'] - self.block_heights[self.tip.sha256] = node.getblock(tip_hash)['height'] - ordered_block(4446, out[18]) yield accepted()