From 3972c7e6b6ec06038233b81795816a5b6155bacc Mon Sep 17 00:00:00 2001 From: Alex Morcos Date: Thu, 19 Jan 2017 22:46:50 -0500 Subject: [PATCH] [test] Remove priority from tests Remove all coin age priority functionality from unit tests and RPC tests. (cherry picked from commit bitcoin/bitcoin@0315888d0db2f39c784afac19ff5db5086f30820) Zcash: * We cannot remove the `pool` parameter from the `CTxMemPool` constructor because we do not have bitcoin/bitcoin#9138. (Backporting that PR is unnecessary and would be a distraction from the purpose of this one; the changes made by it are orthgonal.) * We don't have `prioritise_transaction.py`, `MempoolAncestorIndexingTest`, `MempoolSizeLimitTest`, or the `estimateSmartFee` functionality, so omit the changes for those. Signed-off-by: Daira Emma Hopwood --- qa/rpc-tests/smartfees.py | 13 ++++----- qa/rpc-tests/test_framework/util.py | 41 ----------------------------- src/test/mempool_tests.cpp | 9 +++---- src/test/miner_tests.cpp | 3 +-- src/test/policyestimator_tests.cpp | 6 ++--- src/test/test_bitcoin.cpp | 2 +- src/test/test_bitcoin.h | 4 +-- 7 files changed, 17 insertions(+), 61 deletions(-) diff --git a/qa/rpc-tests/smartfees.py b/qa/rpc-tests/smartfees.py index 33a923328..f2d00c4dd 100755 --- a/qa/rpc-tests/smartfees.py +++ b/qa/rpc-tests/smartfees.py @@ -78,12 +78,13 @@ def small_txpuzzle_randfee(from_node, conflist, unconflist, amount, min_fee, fee return (completetx, fee) def split_inputs(from_node, txins, txouts, initial_split = False): - ''' - We need to generate a lot of very small inputs so we can generate a ton of transactions - and they will have low priority. + """ + We need to generate a lot of inputs so we can generate a ton of transactions. This function takes an input from txins, and creates and sends a transaction which splits the value into 2 outputs which are appended to txouts. - ''' + Previously this was designed to be small inputs so they wouldn't have + a high coin age when the notion of priority still existed. + """ prevtxout = txins.pop() inputs = [] outputs = {} @@ -150,7 +151,7 @@ class EstimateFeeTest(BitcoinTestFramework): def setup_network(self): ''' We'll setup the network to have 3 nodes that all mine with different parameters. - But first we need to use one node to create a lot of small low priority outputs + But first we need to use one node to create a lot of outputs which we will use to generate our transactions. ''' self.nodes = [] @@ -159,7 +160,7 @@ class EstimateFeeTest(BitcoinTestFramework): "-whitelist=127.0.0.1"])) print("This test is time consuming, please be patient") - print("Splitting inputs to small size so we can generate low priority tx's") + print("Splitting inputs so we can generate tx's") self.txouts = [] self.txouts2 = [] # Split a coinbase into two transaction puzzle outputs diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 143ff9027..f678d268c 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -552,47 +552,6 @@ def make_change(from_node, amount_in, amount_out, fee): outputs[from_node.getnewaddress()] = change return outputs -def send_zeropri_transaction(from_node, to_node, amount, fee): - """ - Create&broadcast a zero-priority transaction. - Returns (txid, hex-encoded-txdata) - Ensures transaction is zero-priority by first creating a send-to-self, - then using its output - """ - - # Create a send-to-self with confirmed inputs: - self_address = from_node.getnewaddress() - (total_in, inputs) = gather_inputs(from_node, amount+fee*2) - outputs = make_change(from_node, total_in, amount+fee, fee) - outputs[self_address] = float(amount+fee) - - self_rawtx = from_node.createrawtransaction(inputs, outputs) - self_signresult = from_node.signrawtransaction(self_rawtx) - self_txid = from_node.sendrawtransaction(self_signresult["hex"], True) - - vout = find_output(from_node, self_txid, amount+fee) - # Now immediately spend the output to create a 1-input, 1-output - # zero-priority transaction: - inputs = [ { "txid" : self_txid, "vout" : vout } ] - outputs = { to_node.getnewaddress() : float(amount) } - - rawtx = from_node.createrawtransaction(inputs, outputs) - signresult = from_node.signrawtransaction(rawtx) - txid = from_node.sendrawtransaction(signresult["hex"], True) - - return (txid, signresult["hex"]) - -def random_zeropri_transaction(nodes, amount, min_fee, fee_increment, fee_variants): - """ - Create a random zero-priority transaction. - Returns (txid, hex-encoded-transaction-data, fee) - """ - from_node = random.choice(nodes) - to_node = random.choice(nodes) - fee = min_fee + fee_increment*random.randint(0,fee_variants) - (txid, txhex) = send_zeropri_transaction(from_node, to_node, amount, fee) - return (txid, txhex, fee) - def random_transaction(nodes, amount, min_fee, fee_increment, fee_variants): """ Create a random transaction. diff --git a/src/test/mempool_tests.cpp b/src/test/mempool_tests.cpp index 20ae5bea7..66ab933ad 100644 --- a/src/test/mempool_tests.cpp +++ b/src/test/mempool_tests.cpp @@ -127,28 +127,28 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest) tx1.vout.resize(1); tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; tx1.vout[0].nValue = 10 * COIN; - pool.addUnchecked(tx1.GetHash(), entry.Fee(10000LL).Priority(10.0).FromTx(tx1)); + pool.addUnchecked(tx1.GetHash(), entry.Fee(10000LL).FromTx(tx1)); /* highest fee */ CMutableTransaction tx2 = CMutableTransaction(); tx2.vout.resize(1); tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; tx2.vout[0].nValue = 2 * COIN; - pool.addUnchecked(tx2.GetHash(), entry.Fee(20000LL).Priority(9.0).FromTx(tx2)); + pool.addUnchecked(tx2.GetHash(), entry.Fee(20000LL).FromTx(tx2)); /* lowest fee */ CMutableTransaction tx3 = CMutableTransaction(); tx3.vout.resize(1); tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; tx3.vout[0].nValue = 5 * COIN; - pool.addUnchecked(tx3.GetHash(), entry.Fee(0LL).Priority(100.0).FromTx(tx3)); + pool.addUnchecked(tx3.GetHash(), entry.Fee(0LL).FromTx(tx3)); /* 2nd highest fee */ CMutableTransaction tx4 = CMutableTransaction(); tx4.vout.resize(1); tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; tx4.vout[0].nValue = 6 * COIN; - pool.addUnchecked(tx4.GetHash(), entry.Fee(15000LL).Priority(1.0).FromTx(tx4)); + pool.addUnchecked(tx4.GetHash(), entry.Fee(15000LL).FromTx(tx4)); /* equal fee rate to tx1, but newer */ CMutableTransaction tx5 = CMutableTransaction(); @@ -156,7 +156,6 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest) tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; tx5.vout[0].nValue = 11 * COIN; entry.nTime = 1; - entry.dPriority = 10.0; pool.addUnchecked(tx5.GetHash(), entry.Fee(10000LL).FromTx(tx5)); BOOST_CHECK_EQUAL(pool.size(), 5); diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index fab302b63..1c5c9dbee 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -161,7 +161,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) uint256 hash; TestMemPoolEntryHelper entry; entry.nFee = 11; - entry.dPriority = 111.0; entry.nHeight = 11; LOCK(cs_main); @@ -354,7 +353,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) BOOST_CHECK_EXCEPTION(BlockAssembler(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, err_is("bad-txns-inputs-missingorspent")); mempool.clear(); - // child with higher priority than parent + // child with higher feerate than parent tx.vin[0].scriptSig = CScript() << OP_1; tx.vin[0].prevout.hash = txFirst[1]->GetHash(); tx.vout[0].nValue = BLOCKSUBSIDY-HIGHFEE; diff --git a/src/test/policyestimator_tests.cpp b/src/test/policyestimator_tests.cpp index e6472826a..add0215a3 100644 --- a/src/test/policyestimator_tests.cpp +++ b/src/test/policyestimator_tests.cpp @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) for (int k = 0; k < 4; k++) { // add 4 fee txs tx.vin[0].prevout.n = 10000*blocknum+100*j+k; // make transaction unique uint256 hash = tx.GetHash(); - mpool.addUnchecked(hash, entry.Fee(feeV[j]).Time(GetTime()).Priority(0).Height(blocknum).FromTx(tx, &mpool)); + mpool.addUnchecked(hash, entry.Fee(feeV[j]).Time(GetTime()).Height(blocknum).FromTx(tx, &mpool)); txHashes[j].push_back(hash); } } @@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) for (int k = 0; k < 4; k++) { // add 4 fee txs tx.vin[0].prevout.n = 10000*blocknum+100*j+k; uint256 hash = tx.GetHash(); - mpool.addUnchecked(hash, entry.Fee(feeV[j]).Time(GetTime()).Priority(0).Height(blocknum).FromTx(tx, &mpool)); + mpool.addUnchecked(hash, entry.Fee(feeV[j]).Time(GetTime()).Height(blocknum).FromTx(tx, &mpool)); txHashes[j].push_back(hash); } } @@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) for (int k = 0; k < 4; k++) { // add 4 fee txs tx.vin[0].prevout.n = 10000*blocknum+100*j+k; uint256 hash = tx.GetHash(); - mpool.addUnchecked(hash, entry.Fee(feeV[j]).Time(GetTime()).Priority(0).Height(blocknum).FromTx(tx, &mpool)); + mpool.addUnchecked(hash, entry.Fee(feeV[j]).Time(GetTime()).Height(blocknum).FromTx(tx, &mpool)); std::shared_ptr ptx = mpool.get(hash); if (ptx) block.push_back(*ptx); diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index 715a9ec1b..5be6d1e03 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -231,7 +231,7 @@ CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(CMutableTransaction &tx, CTxMemPo CTransaction txn(tx); bool hasNoDependencies = pool ? pool->HasNoInputsOf(tx) : hadNoDependencies; - return CTxMemPoolEntry(txn, nFee, nTime, dPriority, nHeight, + return CTxMemPoolEntry(txn, nFee, nTime, 0.0, nHeight, hasNoDependencies, spendsCoinbase, sigOpCount, nBranchId); } diff --git a/src/test/test_bitcoin.h b/src/test/test_bitcoin.h index 4c1c060df..9b3c1da6c 100644 --- a/src/test/test_bitcoin.h +++ b/src/test/test_bitcoin.h @@ -86,7 +86,6 @@ struct TestMemPoolEntryHelper // Default values CAmount nFee; int64_t nTime; - double dPriority; unsigned int nHeight; bool hadNoDependencies; bool spendsCoinbase; @@ -94,7 +93,7 @@ struct TestMemPoolEntryHelper uint32_t nBranchId; TestMemPoolEntryHelper() : - nFee(0), nTime(0), dPriority(0.0), nHeight(1), + nFee(0), nTime(0), nHeight(1), hadNoDependencies(false), spendsCoinbase(false), sigOpCount(1), nBranchId(SPROUT_BRANCH_ID) { } @@ -103,7 +102,6 @@ struct TestMemPoolEntryHelper // Change the default value TestMemPoolEntryHelper &Fee(CAmount _fee) { nFee = _fee; return *this; } TestMemPoolEntryHelper &Time(int64_t _time) { nTime = _time; return *this; } - TestMemPoolEntryHelper &Priority(double _priority) { dPriority = _priority; return *this; } TestMemPoolEntryHelper &Height(unsigned int _height) { nHeight = _height; return *this; } TestMemPoolEntryHelper &HadNoDependencies(bool _hnd) { hadNoDependencies = _hnd; return *this; } TestMemPoolEntryHelper &SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }