Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_unbroadcast.py
Show All 10 Lines | |||||
from test_framework.mininode import P2PTxInvStore | 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, | ||||
connect_nodes, | connect_nodes, | ||||
disconnect_nodes, | disconnect_nodes, | ||||
) | ) | ||||
# 15 minutes in seconds | |||||
MAX_INITIAL_BROADCAST_DELAY = 15 * 60 | |||||
class MempoolUnbroadcastTest(BitcoinTestFramework): | class MempoolUnbroadcastTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def test_broadcast(self): | ||||
# ensure that unbroadcast txs are persisted to mempool.dat | # ensure that unbroadcast txs are persisted to mempool.dat | ||||
self.restart_node(0) | self.restart_node(0) | ||||
self.log.info("Reconnect nodes & check if they are sent to node 1") | self.log.info("Reconnect nodes & check if they are sent to node 1") | ||||
connect_nodes(node, self.nodes[1]) | connect_nodes(node, self.nodes[1]) | ||||
# fast forward into the future & ensure that the second node has the | # fast forward into the future & ensure that the second node has the | ||||
# txns | # txns | ||||
node.mockscheduler(15 * 60) # 15 min in seconds | node.mockscheduler(MAX_INITIAL_BROADCAST_DELAY) | ||||
self.sync_mempools(timeout=30) | self.sync_mempools(timeout=30) | ||||
mempool = self.nodes[1].getrawmempool() | mempool = self.nodes[1].getrawmempool() | ||||
assert rpc_tx_hsh in mempool | assert rpc_tx_hsh in mempool | ||||
assert wallet_tx_hsh in mempool | assert wallet_tx_hsh in mempool | ||||
# check that transactions are no longer in first node's unbroadcast set | # check that transactions are no longer in first node's unbroadcast set | ||||
mempool = self.nodes[0].getrawmempool(True) | mempool = self.nodes[0].getrawmempool(True) | ||||
for tx in mempool: | for tx in mempool: | ||||
assert_equal(mempool[tx]['unbroadcast'], False) | assert_equal(mempool[tx]['unbroadcast'], False) | ||||
self.log.info( | self.log.info( | ||||
"Add another connection & ensure transactions aren't broadcast again") | "Add another connection & ensure transactions aren't broadcast again") | ||||
conn = node.add_p2p_connection(P2PTxInvStore()) | conn = node.add_p2p_connection(P2PTxInvStore()) | ||||
node.mockscheduler(15 * 60) | node.mockscheduler(MAX_INITIAL_BROADCAST_DELAY) | ||||
time.sleep(5) | # allow sufficient time for possibility of broadcast | ||||
time.sleep(2) | |||||
assert_equal(len(conn.get_invs()), 0) | assert_equal(len(conn.get_invs()), 0) | ||||
disconnect_nodes(node, self.nodes[1]) | |||||
node.disconnect_p2ps() | |||||
def test_txn_removal(self): | def test_txn_removal(self): | ||||
self.log.info( | self.log.info( | ||||
"Test that transactions removed from mempool are removed from unbroadcast set") | "Test that transactions removed from mempool are removed from unbroadcast set") | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
disconnect_nodes(node, self.nodes[1]) | |||||
node.disconnect_p2ps() | |||||
# since the node doesn't have any connections, it will not receive | # since the node doesn't have any connections, it will not receive | ||||
# any GETDATAs & thus the transaction will remain in the unbroadcast | # any GETDATAs & thus the transaction will remain in the unbroadcast | ||||
# set. | # set. | ||||
addr = node.getnewaddress() | addr = node.getnewaddress() | ||||
txhsh = node.sendtoaddress(addr, 0.0001) | txhsh = node.sendtoaddress(addr, 0.0001) | ||||
# check transaction was removed from unbroadcast set due to presence in | # check transaction was removed from unbroadcast set due to presence in | ||||
Show All 9 Lines |