Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_packages.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2019 The Bitcoin Core developers | # Copyright (c) 2014-2019 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test descendant package tracking code.""" | """Test descendant package tracking code.""" | ||||
from decimal import Decimal | from decimal import Decimal | ||||
from test_framework.messages import COIN | from test_framework.messages import COIN | ||||
from test_framework.mininode import P2PTxInvStore | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
satoshi_round, | satoshi_round, | ||||
) | ) | ||||
# default limits | # default limits | ||||
Show All 29 Lines | def chain_transaction(self, node, parent_txid, vout, | ||||
txid = node.sendrawtransaction(signedtx['hex']) | txid = node.sendrawtransaction(signedtx['hex']) | ||||
fulltx = node.getrawtransaction(txid, 1) | fulltx = node.getrawtransaction(txid, 1) | ||||
# make sure we didn't generate a change output | # make sure we didn't generate a change output | ||||
assert len(fulltx['vout']) == num_outputs | assert len(fulltx['vout']) == num_outputs | ||||
return (txid, send_value) | return (txid, send_value) | ||||
def run_test(self): | def run_test(self): | ||||
# Mine some blocks and have them mature. | # Mine some blocks and have them mature. | ||||
# keep track of invs | |||||
self.nodes[0].add_p2p_connection(P2PTxInvStore()) | |||||
self.nodes[0].generate(101) | self.nodes[0].generate(101) | ||||
utxo = self.nodes[0].listunspent(10) | utxo = self.nodes[0].listunspent(10) | ||||
txid = utxo[0]['txid'] | txid = utxo[0]['txid'] | ||||
vout = utxo[0]['vout'] | vout = utxo[0]['vout'] | ||||
value = utxo[0]['amount'] | value = utxo[0]['amount'] | ||||
fee = Decimal("0.0001") | fee = Decimal("0.0001") | ||||
# MAX_ANCESTORS transactions off a confirmed tx should be fine | # MAX_ANCESTORS transactions off a confirmed tx should be fine | ||||
chain = [] | chain = [] | ||||
for i in range(MAX_ANCESTORS): | for i in range(MAX_ANCESTORS): | ||||
(txid, sent_value) = self.chain_transaction( | (txid, sent_value) = self.chain_transaction( | ||||
self.nodes[0], txid, 0, value, fee, 1) | self.nodes[0], txid, 0, value, fee, 1) | ||||
value = sent_value | value = sent_value | ||||
chain.append(txid) | chain.append(txid) | ||||
# Wait until mempool transactions have passed initial broadcast | |||||
# (sent inv and received getdata) | |||||
# Otherwise, getrawmempool may be inconsistent with getmempoolentry if | |||||
# unbroadcast changes in between | |||||
self.nodes[0].p2p.wait_for_broadcast(chain) | |||||
# Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor | # Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor | ||||
# count and fees should look correct | # count and fees should look correct | ||||
mempool = self.nodes[0].getrawmempool(True) | mempool = self.nodes[0].getrawmempool(True) | ||||
assert_equal(len(mempool), MAX_ANCESTORS) | assert_equal(len(mempool), MAX_ANCESTORS) | ||||
descendant_count = 1 | descendant_count = 1 | ||||
descendant_fees = 0 | descendant_fees = 0 | ||||
descendant_size = 0 | descendant_size = 0 | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Check that node1's mempool is as expected (-> custom ancestor limit) | # Check that node1's mempool is as expected (-> custom ancestor limit) | ||||
mempool0 = self.nodes[0].getrawmempool(False) | mempool0 = self.nodes[0].getrawmempool(False) | ||||
mempool1 = self.nodes[1].getrawmempool(False) | mempool1 = self.nodes[1].getrawmempool(False) | ||||
assert_equal(len(mempool1), MAX_ANCESTORS_CUSTOM) | assert_equal(len(mempool1), MAX_ANCESTORS_CUSTOM) | ||||
assert set(mempool1).issubset(set(mempool0)) | assert set(mempool1).issubset(set(mempool0)) | ||||
for tx in chain[:MAX_ANCESTORS_CUSTOM]: | for tx in chain[:MAX_ANCESTORS_CUSTOM]: | ||||
assert tx in mempool1 | assert tx in mempool1 | ||||
# TODO: more detailed check of node1's mempool (fees etc.) | # TODO: more detailed check of node1's mempool (fees etc.) | ||||
# check transaction unbroadcast info (should be false if in both | |||||
# mempools) | |||||
mempool = self.nodes[0].getrawmempool(True) | |||||
for tx in mempool: | |||||
assert_equal(mempool[tx]['unbroadcast'], False) | |||||
# TODO: test ancestor size limits | # TODO: test ancestor size limits | ||||
# Now test descendant chain limits | # Now test descendant chain limits | ||||
txid = utxo[1]['txid'] | txid = utxo[1]['txid'] | ||||
value = utxo[1]['amount'] | value = utxo[1]['amount'] | ||||
vout = utxo[1]['vout'] | vout = utxo[1]['vout'] | ||||
▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines |