From 2e9e818f1fc28a7112a5a13a5974cb6ad58c062d Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 14 Mar 2019 20:20:03 +0300 Subject: [PATCH 1/2] No free non-prioritised txes can be mined/relayed now --- qa/rpc-tests/addressindex.py | 21 +++++++++++---------- qa/rpc-tests/mempool_spendcoinbase.py | 8 ++++---- qa/rpc-tests/merkle_blocks.py | 13 +++++++------ qa/rpc-tests/spentindex.py | 14 ++++++++------ qa/rpc-tests/wallet.py | 15 +++++++++------ 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/qa/rpc-tests/addressindex.py b/qa/rpc-tests/addressindex.py index f3ea0f53975a..fdf4c39349ef 100755 --- a/qa/rpc-tests/addressindex.py +++ b/qa/rpc-tests/addressindex.py @@ -120,7 +120,7 @@ def run_test(self): tx.rehash() signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8")) - sent_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True, False, True) + sent_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True) self.nodes[0].generate(1) self.sync_all() @@ -144,12 +144,13 @@ def run_test(self): unspent = self.nodes[0].listunspent() tx = CTransaction() + tx_fee_sat = 1000 tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))] - amount = int(unspent[0]["amount"] * 100000000) + amount = int(unspent[0]["amount"] * 100000000) - tx_fee_sat tx.vout = [CTxOut(amount, scriptPubKey2)] tx.rehash() signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8")) - spending_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True, False, True) + spending_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True) self.nodes[0].generate(1) self.sync_all() balance1 = self.nodes[1].getaddressbalance(address2) @@ -163,7 +164,7 @@ def run_test(self): tx.rehash() signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8")) - sent_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True, False, True) + sent_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True) self.nodes[0].generate(1) self.sync_all() @@ -241,17 +242,17 @@ def run_test(self): tx = CTransaction() tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))] - amount = int(unspent[0]["amount"] * 100000000) + amount = int(unspent[0]["amount"] * 100000000) - tx_fee_sat tx.vout = [CTxOut(amount, scriptPubKey3)] tx.rehash() signed_tx = self.nodes[2].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8")) - memtxid1 = self.nodes[2].sendrawtransaction(signed_tx["hex"], True, False, True) + memtxid1 = self.nodes[2].sendrawtransaction(signed_tx["hex"], True) set_mocktime(get_mocktime() + 2) set_node_times(self.nodes, get_mocktime()) tx2 = CTransaction() tx2.vin = [CTxIn(COutPoint(int(unspent[1]["txid"], 16), unspent[1]["vout"]))] - amount = int(unspent[1]["amount"] * 100000000) + amount = int(unspent[1]["amount"] * 100000000) - tx_fee_sat tx2.vout = [ CTxOut(int(amount / 4), scriptPubKey3), CTxOut(int(amount / 4), scriptPubKey3), @@ -260,7 +261,7 @@ def run_test(self): ] tx2.rehash() signed_tx2 = self.nodes[2].signrawtransaction(binascii.hexlify(tx2.serialize()).decode("utf-8")) - memtxid2 = self.nodes[2].sendrawtransaction(signed_tx2["hex"], True, False, True) + memtxid2 = self.nodes[2].sendrawtransaction(signed_tx2["hex"], True) set_mocktime(get_mocktime() + 2) set_node_times(self.nodes, get_mocktime()) @@ -288,7 +289,7 @@ def run_test(self): tx.rehash() self.nodes[2].importprivkey(privKey3) signed_tx3 = self.nodes[2].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8")) - memtxid3 = self.nodes[2].sendrawtransaction(signed_tx3["hex"], True, False, True) + memtxid3 = self.nodes[2].sendrawtransaction(signed_tx3["hex"], True) set_mocktime(get_mocktime() + 2) set_node_times(self.nodes, get_mocktime()) @@ -321,7 +322,7 @@ def run_test(self): tx.rehash() self.nodes[0].importprivkey(privkey1) signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8")) - mem_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True, False, True) + mem_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True) self.sync_all() mempool_deltas = self.nodes[2].getaddressmempool({"addresses": [address1]}) diff --git a/qa/rpc-tests/mempool_spendcoinbase.py b/qa/rpc-tests/mempool_spendcoinbase.py index 53622e54babd..88c4a44cc222 100755 --- a/qa/rpc-tests/mempool_spendcoinbase.py +++ b/qa/rpc-tests/mempool_spendcoinbase.py @@ -40,12 +40,12 @@ def run_test(self): # is too immature to spend. b = [ self.nodes[0].getblockhash(n) for n in range(101, 103) ] coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ] - spends_raw = [ create_tx(self.nodes[0], txid, node0_address, 500) for txid in coinbase_txids ] + spends_raw = [ create_tx(self.nodes[0], txid, node0_address, 500 - Decimal('0.00001')) for txid in coinbase_txids ] - spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0], False, False, True) + spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0]) # coinbase at height 102 should be too immature to spend - assert_raises(JSONRPCException, self.nodes[0].sendrawtransaction, spends_raw[1], False, False, True) + assert_raises(JSONRPCException, self.nodes[0].sendrawtransaction, spends_raw[1]) # mempool should have just spend_101: assert_equal(self.nodes[0].getrawmempool(), [ spend_101_id ]) @@ -55,7 +55,7 @@ def run_test(self): assert_equal(set(self.nodes[0].getrawmempool()), set()) # ... and now height 102 can be spent: - spend_102_id = self.nodes[0].sendrawtransaction(spends_raw[1], False, False, True) + spend_102_id = self.nodes[0].sendrawtransaction(spends_raw[1]) assert_equal(self.nodes[0].getrawmempool(), [ spend_102_id ]) if __name__ == '__main__': diff --git a/qa/rpc-tests/merkle_blocks.py b/qa/rpc-tests/merkle_blocks.py index a43eccfa095e..b5f6fcbd83ac 100755 --- a/qa/rpc-tests/merkle_blocks.py +++ b/qa/rpc-tests/merkle_blocks.py @@ -39,11 +39,12 @@ def run_test(self): assert_equal(self.nodes[1].getbalance(), 0) assert_equal(self.nodes[2].getbalance(), 0) + tx_fee = Decimal('0.00001') node0utxos = self.nodes[0].listunspent(1) - tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 500}) - txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx1)["hex"], False, False, True) - tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 500}) - txid2 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx2)["hex"], False, False, True) + tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 500 - tx_fee}) + txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx1)["hex"]) + tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 500 - tx_fee}) + txid2 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx2)["hex"]) assert_raises(JSONRPCException, self.nodes[0].gettxoutproof, [txid1]) self.nodes[0].generate(1) @@ -60,8 +61,8 @@ def run_test(self): assert_equal(self.nodes[2].verifytxoutproof(self.nodes[2].gettxoutproof([txid1, txid2], blockhash)), txlist) txin_spent = self.nodes[1].listunspent(1).pop() - tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): 500}) - self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3)["hex"], False, False, True) + tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): 500 - tx_fee*2}) + self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3)["hex"]) self.nodes[0].generate(1) self.sync_all() diff --git a/qa/rpc-tests/spentindex.py b/qa/rpc-tests/spentindex.py index d01624a83844..5147f275b168 100755 --- a/qa/rpc-tests/spentindex.py +++ b/qa/rpc-tests/spentindex.py @@ -52,13 +52,15 @@ def run_test(self): scriptPubKey = CScript([OP_DUP, OP_HASH160, addressHash, OP_EQUALVERIFY, OP_CHECKSIG]) unspent = self.nodes[0].listunspent() tx = CTransaction() - amount = int(unspent[0]["amount"] * COIN) + tx_fee = Decimal('0.00001') + tx_fee_sat = int(tx_fee * COIN) + amount = int(unspent[0]["amount"] * COIN) - tx_fee_sat tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))] tx.vout = [CTxOut(amount, scriptPubKey)] tx.rehash() signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8")) - txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True, False, True) + txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True) self.nodes[0].generate(1) self.sync_all() @@ -81,7 +83,7 @@ def run_test(self): # Check that verbose raw transaction includes input values txVerbose2 = self.nodes[3].getrawtransaction(txid, 1) assert_equal(txVerbose2["vin"][0]["value"], Decimal(unspent[0]["amount"])) - assert_equal(txVerbose2["vin"][0]["valueSat"], amount) + assert_equal(txVerbose2["vin"][0]["valueSat"] - tx_fee_sat, amount) # Check that verbose raw transaction includes address values and input values privkey2 = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc" @@ -94,13 +96,13 @@ def run_test(self): tx2.rehash() self.nodes[0].importprivkey(privkey) signed_tx2 = self.nodes[0].signrawtransaction(binascii.hexlify(tx2.serialize()).decode("utf-8")) - txid2 = self.nodes[0].sendrawtransaction(signed_tx2["hex"], True, False, True) + txid2 = self.nodes[0].sendrawtransaction(signed_tx2["hex"], True) # Check the mempool index self.sync_all() txVerbose3 = self.nodes[1].getrawtransaction(txid2, 1) assert_equal(txVerbose3["vin"][0]["address"], address2) - assert_equal(txVerbose3["vin"][0]["value"], Decimal(unspent[0]["amount"])) + assert_equal(txVerbose3["vin"][0]["value"], Decimal(unspent[0]["amount"]) - tx_fee) assert_equal(txVerbose3["vin"][0]["valueSat"], amount) # Check the database index @@ -109,7 +111,7 @@ def run_test(self): txVerbose4 = self.nodes[3].getrawtransaction(txid2, 1) assert_equal(txVerbose4["vin"][0]["address"], address2) - assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"])) + assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]) - tx_fee) assert_equal(txVerbose4["vin"][0]["valueSat"], amount) self.log.info("Passed") diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index cb34cafe77a3..c43447b99950 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -92,27 +92,30 @@ def run_test (self): node0utxos = self.nodes[0].listunspent(1) assert_equal(len(node0utxos), 2) + fee_per_input = Decimal('0.00001') + totalfee = 0 # create both transactions txns_to_send = [] for utxo in node0utxos: inputs = [] outputs = {} inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]}) - outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"] + outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"] - fee_per_input raw_tx = self.nodes[0].createrawtransaction(inputs, outputs) txns_to_send.append(self.nodes[0].signrawtransaction(raw_tx)) + totalfee += fee_per_input # Have node 1 (miner) send the transactions - self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"], True, False, True) - self.nodes[1].sendrawtransaction(txns_to_send[1]["hex"], True, False, True) + self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"]) + self.nodes[1].sendrawtransaction(txns_to_send[1]["hex"]) # Have node1 mine a block to confirm transactions: self.nodes[1].generate(1) self.sync_all() assert_equal(self.nodes[0].getbalance(), 0) - assert_equal(self.nodes[2].getbalance(), 1000) - assert_equal(self.nodes[2].getbalance("from1"), 1000-210) + assert_equal(self.nodes[2].getbalance(), 1000 - totalfee) + assert_equal(self.nodes[2].getbalance("from1"), 1000 - 210 - totalfee) # Send 100 DASH normal address = self.nodes[0].getnewaddress("test") @@ -121,7 +124,7 @@ def run_test (self): txid = self.nodes[2].sendtoaddress(address, 100, "", "", False) self.nodes[2].generate(1) self.sync_all() - node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('900'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid))) + node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('900') - totalfee, fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid))) assert_equal(self.nodes[0].getbalance(), Decimal('100')) # Send 100 DASH with subtract fee from amount From fcf1ed9c1d62819aacfaaa49cc7a96f7d171528c Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 15 Mar 2019 02:32:47 +0300 Subject: [PATCH 2/2] fix typo --- qa/rpc-tests/prioritise_transaction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/rpc-tests/prioritise_transaction.py b/qa/rpc-tests/prioritise_transaction.py index 9d7dcdfed908..c503f3e12107 100755 --- a/qa/rpc-tests/prioritise_transaction.py +++ b/qa/rpc-tests/prioritise_transaction.py @@ -131,7 +131,7 @@ def run_test(self): mock_time = get_mocktime() self.nodes[0].setmocktime(mock_time) template = self.nodes[0].getblocktemplate() - self.nodes[0].prioritisetransaction(tx2_id, -int(self.relayfee*COIN)) + self.nodes[0].prioritisetransaction(tx_id, -int(self.relayfee*COIN)) self.nodes[0].setmocktime(mock_time+10) new_template = self.nodes[0].getblocktemplate()