mirror of https://github.com/bitcoin/bitcoin.git
test: make notfound_on_unannounced more reliable
By using mocktime, we will always hit both the notfound branch and the tx sent branch. The previous version didn't achieve that due to timing issues. Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
This commit is contained in:
parent
99bc552980
commit
14ae71f323
|
@ -102,27 +102,31 @@ class P2PLeakTxTest(BitcoinTestFramework):
|
||||||
self.gen_node.disconnect_p2ps()
|
self.gen_node.disconnect_p2ps()
|
||||||
inbound_peer = self.gen_node.add_p2p_connection(P2PNode()) # An "attacking" inbound peer
|
inbound_peer = self.gen_node.add_p2p_connection(P2PNode()) # An "attacking" inbound peer
|
||||||
|
|
||||||
MAX_REPEATS = 100
|
# Set a mock time so that time does not pass, and gen_node never announces the transaction
|
||||||
self.log.info("Running test up to {} times.".format(MAX_REPEATS))
|
self.gen_node.setmocktime(self.mocktime)
|
||||||
for i in range(MAX_REPEATS):
|
wtxid = int(self.miniwallet.send_self_transfer(from_node=self.gen_node)["wtxid"], 16)
|
||||||
self.log.info('Run repeat {}'.format(i + 1))
|
|
||||||
wtxid = self.miniwallet.send_self_transfer(from_node=self.gen_node)["wtxid"]
|
|
||||||
|
|
||||||
want_tx = msg_getdata()
|
want_tx = msg_getdata()
|
||||||
want_tx.inv.append(CInv(t=MSG_WTX, h=int(wtxid, 16)))
|
want_tx.inv.append(CInv(t=MSG_WTX, h=wtxid))
|
||||||
with p2p_lock:
|
with p2p_lock:
|
||||||
inbound_peer.last_message.pop('notfound', None)
|
inbound_peer.last_message.pop('notfound', None)
|
||||||
inbound_peer.send_and_ping(want_tx)
|
inbound_peer.send_and_ping(want_tx)
|
||||||
if inbound_peer.last_message.get('notfound'):
|
inbound_peer.wait_until(lambda: "notfound" in inbound_peer.last_message)
|
||||||
self.log.debug('tx {} was not yet announced to us.'.format(wtxid))
|
with p2p_lock:
|
||||||
self.log.debug("node has responded with a notfound message. End test.")
|
assert_equal(inbound_peer.last_message.get("notfound").vec[0].hash, wtxid)
|
||||||
assert_equal(inbound_peer.last_message['notfound'].vec[0].hash, int(wtxid, 16))
|
inbound_peer.last_message.pop('notfound')
|
||||||
with p2p_lock:
|
|
||||||
inbound_peer.last_message.pop('notfound')
|
# Move mocktime forward and wait for the announcement.
|
||||||
break
|
inbound_peer.last_message.pop('inv', None)
|
||||||
else:
|
self.mocktime += 120
|
||||||
self.log.debug('tx {} was already announced to us. Try test again.'.format(wtxid))
|
self.gen_node.setmocktime(self.mocktime)
|
||||||
assert int(wtxid, 16) in [inv.hash for inv in inbound_peer.last_message['inv'].inv]
|
inbound_peer.wait_for_inv([CInv(t=MSG_WTX, h=wtxid)], timeout=120)
|
||||||
|
|
||||||
|
# Send the getdata again, this time the node should send us a TX message.
|
||||||
|
inbound_peer.last_message.pop('tx', None)
|
||||||
|
inbound_peer.send_and_ping(want_tx)
|
||||||
|
self.wait_until(lambda: "tx" in inbound_peer.last_message)
|
||||||
|
assert_equal(wtxid, int(inbound_peer.last_message["tx"].tx.wtxid_hex, 16))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue