Skip to content

Commit

Permalink
test: Use wtxid relay generally in functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fjahr authored and sdaftuar committed Jul 19, 2020
1 parent 8d8099e commit cacd852
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
7 changes: 6 additions & 1 deletion test/functional/mempool_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,19 @@ def run_test(self):
fee = Decimal("0.0001")
# MAX_ANCESTORS transactions off a confirmed tx should be fine
chain = []
witness_chain = []
for i in range(MAX_ANCESTORS):
(txid, sent_value) = self.chain_transaction(self.nodes[0], txid, 0, value, fee, 1)
value = sent_value
chain.append(txid)
# We need the wtxids to check P2P announcements
fulltx = self.nodes[0].getrawtransaction(txid)
witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
witness_chain.append(witnesstx['hash'])

# 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)
self.nodes[0].p2p.wait_for_broadcast(witness_chain)

# Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor
# count and fees should look correct
Expand Down
2 changes: 1 addition & 1 deletion test/functional/p2p_blocksonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def run_test(self):
self.log.info('Check that txs from rpc are not rejected and relayed to other peers')
assert_equal(self.nodes[0].getpeerinfo()[0]['relaytxes'], True)
txid = self.nodes[0].testmempoolaccept([sigtx])[0]['txid']
with self.nodes[0].assert_debug_log(['received getdata for: tx {} peer=1'.format(txid)]):
with self.nodes[0].assert_debug_log(['received getdata for: wtx {} peer=1'.format(txid)]):
self.nodes[0].sendrawtransaction(sigtx)
self.nodes[0].p2p.wait_for_tx(txid)
assert_equal(self.nodes[0].getmempoolinfo()['size'], 1)
Expand Down
4 changes: 2 additions & 2 deletions test/functional/p2p_feefilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from decimal import Decimal
import time

from test_framework.messages import MSG_TX, msg_feefilter
from test_framework.messages import MSG_TX, MSG_WTX, msg_feefilter
from test_framework.mininode import mininode_lock, P2PInterface
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
Expand Down Expand Up @@ -45,7 +45,7 @@ def __init__(self):

def on_inv(self, message):
for i in message.inv:
if (i.type == MSG_TX):
if (i.type == MSG_TX) or (i.type == MSG_WTX):
self.txinvs.append(hashToHex(i.hash))

def clear_invs(self):
Expand Down
7 changes: 4 additions & 3 deletions test/functional/p2p_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
msg_block,
msg_no_witness_tx,
msg_verack,
msg_wtxidrelay,
ser_uint256,
ser_vector,
sha256,
Expand Down Expand Up @@ -161,8 +160,10 @@ def on_inv(self, message):

def on_version(self, message):
if self.wtxidrelay:
self.send_message(msg_wtxidrelay())
super().on_version(message)
super().on_version(message)
else:
self.send_message(msg_verack())
self.nServices = message.nServices

def on_getdata(self, message):
self.lastgetdata = message.inv
Expand Down
9 changes: 5 additions & 4 deletions test/functional/p2p_tx_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
FromHex,
MSG_TX,
MSG_TYPE_MASK,
MSG_WTX,
msg_inv,
msg_notfound,
)
Expand All @@ -36,7 +37,7 @@ def __init__(self):

def on_getdata(self, message):
for i in message.inv:
if i.type & MSG_TYPE_MASK == MSG_TX:
if i.type & MSG_TYPE_MASK == MSG_TX or i.type & MSG_TYPE_MASK == MSG_WTX:
self.tx_getdata_count += 1


Expand Down Expand Up @@ -64,7 +65,7 @@ def test_tx_requests(self):
txid = 0xdeadbeef

self.log.info("Announce the txid from each incoming peer to node 0")
msg = msg_inv([CInv(t=MSG_TX, h=txid)])
msg = msg_inv([CInv(t=MSG_WTX, h=txid)])
for p in self.nodes[0].p2ps:
p.send_and_ping(msg)

Expand Down Expand Up @@ -136,13 +137,13 @@ def test_in_flight_max(self):
with mininode_lock:
p.tx_getdata_count = 0

p.send_message(msg_inv([CInv(t=MSG_TX, h=i) for i in txids]))
p.send_message(msg_inv([CInv(t=MSG_WTX, h=i) for i in txids]))
wait_until(lambda: p.tx_getdata_count >= MAX_GETDATA_IN_FLIGHT, lock=mininode_lock)
with mininode_lock:
assert_equal(p.tx_getdata_count, MAX_GETDATA_IN_FLIGHT)

self.log.info("Now check that if we send a NOTFOUND for a transaction, we'll get one more request")
p.send_message(msg_notfound(vec=[CInv(t=MSG_TX, h=txids[0])]))
p.send_message(msg_notfound(vec=[CInv(t=MSG_WTX, h=txids[0])]))
wait_until(lambda: p.tx_getdata_count >= MAX_GETDATA_IN_FLIGHT + 1, timeout=10, lock=mininode_lock)
with mininode_lock:
assert_equal(p.tx_getdata_count, MAX_GETDATA_IN_FLIGHT + 1)
Expand Down
2 changes: 2 additions & 0 deletions test/functional/test_framework/mininode.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ def on_verack(self, message):

def on_version(self, message):
assert message.nVersion >= MIN_VERSION_SUPPORTED, "Version {} received. Test framework only supports versions greater than {}".format(message.nVersion, MIN_VERSION_SUPPORTED)
if message.nVersion >= 70016:
self.send_message(msg_wtxidrelay())
self.send_message(msg_verack())
self.nServices = message.nServices

Expand Down

0 comments on commit cacd852

Please sign in to comment.