Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_unbroadcast.py
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | def test_broadcast(self): | ||||
inputs = [{"txid": us0["txid"], "vout": us0["vout"]}] | inputs = [{"txid": us0["txid"], "vout": us0["vout"]}] | ||||
outputs = {addr: 0.0001} | outputs = {addr: 0.0001} | ||||
tx = node.createrawtransaction(inputs, outputs) | tx = node.createrawtransaction(inputs, outputs) | ||||
node.settxfee(min_relay_fee) | node.settxfee(min_relay_fee) | ||||
txF = node.fundrawtransaction(tx) | txF = node.fundrawtransaction(tx) | ||||
txFS = node.signrawtransactionwithwallet(txF["hex"]) | txFS = node.signrawtransactionwithwallet(txF["hex"]) | ||||
rpc_tx_hsh = node.sendrawtransaction(txFS["hex"]) | rpc_tx_hsh = node.sendrawtransaction(txFS["hex"]) | ||||
# check transactions are in unbroadcast using rpc | |||||
mempoolinfo = self.nodes[0].getmempoolinfo() | |||||
assert_equal(mempoolinfo['unbroadcastcount'], 2) | |||||
mempool = self.nodes[0].getrawmempool(True) | |||||
for tx in mempool: | |||||
assert_equal(mempool[tx]['unbroadcast'], True) | |||||
# check that second node doesn't have these two txns | # check that second node doesn't have these two txns | ||||
mempool = self.nodes[1].getrawmempool() | mempool = self.nodes[1].getrawmempool() | ||||
assert rpc_tx_hsh not in mempool | assert rpc_tx_hsh not in mempool | ||||
assert wallet_tx_hsh not in mempool | assert wallet_tx_hsh not in mempool | ||||
# 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(15 * 60) # 15 min in seconds | ||||
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 | |||||
mempool = self.nodes[0].getrawmempool(True) | |||||
for tx in mempool: | |||||
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(15 * 60) | ||||
time.sleep(5) | time.sleep(5) | ||||
assert_equal(len(conn.get_invs()), 0) | assert_equal(len(conn.get_invs()), 0) | ||||
Show All 23 Lines |