[test] Remove priority from tests
Remove all coin age priority functionality from unit tests and RPC tests. (cherry picked from commit bitcoin/bitcoin@0315888d0d) 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 <daira@jacaranda.org>
This commit is contained in:
parent
0d0e046b66
commit
3972c7e6b6
|
@ -78,12 +78,13 @@ def small_txpuzzle_randfee(from_node, conflist, unconflist, amount, min_fee, fee
|
||||||
return (completetx, fee)
|
return (completetx, fee)
|
||||||
|
|
||||||
def split_inputs(from_node, txins, txouts, initial_split = False):
|
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
|
We need to generate a lot of inputs so we can generate a ton of transactions.
|
||||||
and they will have low priority.
|
|
||||||
This function takes an input from txins, and creates and sends a transaction
|
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.
|
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()
|
prevtxout = txins.pop()
|
||||||
inputs = []
|
inputs = []
|
||||||
outputs = {}
|
outputs = {}
|
||||||
|
@ -150,7 +151,7 @@ class EstimateFeeTest(BitcoinTestFramework):
|
||||||
def setup_network(self):
|
def setup_network(self):
|
||||||
'''
|
'''
|
||||||
We'll setup the network to have 3 nodes that all mine with different parameters.
|
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.
|
which we will use to generate our transactions.
|
||||||
'''
|
'''
|
||||||
self.nodes = []
|
self.nodes = []
|
||||||
|
@ -159,7 +160,7 @@ class EstimateFeeTest(BitcoinTestFramework):
|
||||||
"-whitelist=127.0.0.1"]))
|
"-whitelist=127.0.0.1"]))
|
||||||
|
|
||||||
print("This test is time consuming, please be patient")
|
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.txouts = []
|
||||||
self.txouts2 = []
|
self.txouts2 = []
|
||||||
# Split a coinbase into two transaction puzzle outputs
|
# Split a coinbase into two transaction puzzle outputs
|
||||||
|
|
|
@ -552,47 +552,6 @@ def make_change(from_node, amount_in, amount_out, fee):
|
||||||
outputs[from_node.getnewaddress()] = change
|
outputs[from_node.getnewaddress()] = change
|
||||||
return outputs
|
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):
|
def random_transaction(nodes, amount, min_fee, fee_increment, fee_variants):
|
||||||
"""
|
"""
|
||||||
Create a random transaction.
|
Create a random transaction.
|
||||||
|
|
|
@ -127,28 +127,28 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
|
||||||
tx1.vout.resize(1);
|
tx1.vout.resize(1);
|
||||||
tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
||||||
tx1.vout[0].nValue = 10 * COIN;
|
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 */
|
/* highest fee */
|
||||||
CMutableTransaction tx2 = CMutableTransaction();
|
CMutableTransaction tx2 = CMutableTransaction();
|
||||||
tx2.vout.resize(1);
|
tx2.vout.resize(1);
|
||||||
tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
||||||
tx2.vout[0].nValue = 2 * COIN;
|
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 */
|
/* lowest fee */
|
||||||
CMutableTransaction tx3 = CMutableTransaction();
|
CMutableTransaction tx3 = CMutableTransaction();
|
||||||
tx3.vout.resize(1);
|
tx3.vout.resize(1);
|
||||||
tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
||||||
tx3.vout[0].nValue = 5 * COIN;
|
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 */
|
/* 2nd highest fee */
|
||||||
CMutableTransaction tx4 = CMutableTransaction();
|
CMutableTransaction tx4 = CMutableTransaction();
|
||||||
tx4.vout.resize(1);
|
tx4.vout.resize(1);
|
||||||
tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
||||||
tx4.vout[0].nValue = 6 * COIN;
|
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 */
|
/* equal fee rate to tx1, but newer */
|
||||||
CMutableTransaction tx5 = CMutableTransaction();
|
CMutableTransaction tx5 = CMutableTransaction();
|
||||||
|
@ -156,7 +156,6 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
|
||||||
tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
||||||
tx5.vout[0].nValue = 11 * COIN;
|
tx5.vout[0].nValue = 11 * COIN;
|
||||||
entry.nTime = 1;
|
entry.nTime = 1;
|
||||||
entry.dPriority = 10.0;
|
|
||||||
pool.addUnchecked(tx5.GetHash(), entry.Fee(10000LL).FromTx(tx5));
|
pool.addUnchecked(tx5.GetHash(), entry.Fee(10000LL).FromTx(tx5));
|
||||||
BOOST_CHECK_EQUAL(pool.size(), 5);
|
BOOST_CHECK_EQUAL(pool.size(), 5);
|
||||||
|
|
||||||
|
|
|
@ -161,7 +161,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||||
uint256 hash;
|
uint256 hash;
|
||||||
TestMemPoolEntryHelper entry;
|
TestMemPoolEntryHelper entry;
|
||||||
entry.nFee = 11;
|
entry.nFee = 11;
|
||||||
entry.dPriority = 111.0;
|
|
||||||
entry.nHeight = 11;
|
entry.nHeight = 11;
|
||||||
|
|
||||||
LOCK(cs_main);
|
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"));
|
BOOST_CHECK_EXCEPTION(BlockAssembler(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, err_is("bad-txns-inputs-missingorspent"));
|
||||||
mempool.clear();
|
mempool.clear();
|
||||||
|
|
||||||
// child with higher priority than parent
|
// child with higher feerate than parent
|
||||||
tx.vin[0].scriptSig = CScript() << OP_1;
|
tx.vin[0].scriptSig = CScript() << OP_1;
|
||||||
tx.vin[0].prevout.hash = txFirst[1]->GetHash();
|
tx.vin[0].prevout.hash = txFirst[1]->GetHash();
|
||||||
tx.vout[0].nValue = BLOCKSUBSIDY-HIGHFEE;
|
tx.vout[0].nValue = BLOCKSUBSIDY-HIGHFEE;
|
||||||
|
|
|
@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
||||||
for (int k = 0; k < 4; k++) { // add 4 fee txs
|
for (int k = 0; k < 4; k++) { // add 4 fee txs
|
||||||
tx.vin[0].prevout.n = 10000*blocknum+100*j+k; // make transaction unique
|
tx.vin[0].prevout.n = 10000*blocknum+100*j+k; // make transaction unique
|
||||||
uint256 hash = tx.GetHash();
|
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);
|
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
|
for (int k = 0; k < 4; k++) { // add 4 fee txs
|
||||||
tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
|
tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
|
||||||
uint256 hash = tx.GetHash();
|
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);
|
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
|
for (int k = 0; k < 4; k++) { // add 4 fee txs
|
||||||
tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
|
tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
|
||||||
uint256 hash = tx.GetHash();
|
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<const CTransaction> ptx = mpool.get(hash);
|
std::shared_ptr<const CTransaction> ptx = mpool.get(hash);
|
||||||
if (ptx)
|
if (ptx)
|
||||||
block.push_back(*ptx);
|
block.push_back(*ptx);
|
||||||
|
|
|
@ -231,7 +231,7 @@ CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(CMutableTransaction &tx, CTxMemPo
|
||||||
CTransaction txn(tx);
|
CTransaction txn(tx);
|
||||||
bool hasNoDependencies = pool ? pool->HasNoInputsOf(tx) : hadNoDependencies;
|
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);
|
hasNoDependencies, spendsCoinbase, sigOpCount, nBranchId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,6 @@ struct TestMemPoolEntryHelper
|
||||||
// Default values
|
// Default values
|
||||||
CAmount nFee;
|
CAmount nFee;
|
||||||
int64_t nTime;
|
int64_t nTime;
|
||||||
double dPriority;
|
|
||||||
unsigned int nHeight;
|
unsigned int nHeight;
|
||||||
bool hadNoDependencies;
|
bool hadNoDependencies;
|
||||||
bool spendsCoinbase;
|
bool spendsCoinbase;
|
||||||
|
@ -94,7 +93,7 @@ struct TestMemPoolEntryHelper
|
||||||
uint32_t nBranchId;
|
uint32_t nBranchId;
|
||||||
|
|
||||||
TestMemPoolEntryHelper() :
|
TestMemPoolEntryHelper() :
|
||||||
nFee(0), nTime(0), dPriority(0.0), nHeight(1),
|
nFee(0), nTime(0), nHeight(1),
|
||||||
hadNoDependencies(false), spendsCoinbase(false), sigOpCount(1),
|
hadNoDependencies(false), spendsCoinbase(false), sigOpCount(1),
|
||||||
nBranchId(SPROUT_BRANCH_ID) { }
|
nBranchId(SPROUT_BRANCH_ID) { }
|
||||||
|
|
||||||
|
@ -103,7 +102,6 @@ struct TestMemPoolEntryHelper
|
||||||
// Change the default value
|
// Change the default value
|
||||||
TestMemPoolEntryHelper &Fee(CAmount _fee) { nFee = _fee; return *this; }
|
TestMemPoolEntryHelper &Fee(CAmount _fee) { nFee = _fee; return *this; }
|
||||||
TestMemPoolEntryHelper &Time(int64_t _time) { nTime = _time; 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 &Height(unsigned int _height) { nHeight = _height; return *this; }
|
||||||
TestMemPoolEntryHelper &HadNoDependencies(bool _hnd) { hadNoDependencies = _hnd; return *this; }
|
TestMemPoolEntryHelper &HadNoDependencies(bool _hnd) { hadNoDependencies = _hnd; return *this; }
|
||||||
TestMemPoolEntryHelper &SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }
|
TestMemPoolEntryHelper &SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }
|
||||||
|
|
Loading…
Reference in New Issue