mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
f1885c2221
651f1d816f054cb9c637f8a99c9360bba381ef58 [test] wait for inital broadcast before comparing mempool entries (gzhao408) 9d3f7eb9860254eb787ebe2734fd6a26bcf365c1 [mempool] sanity check that all unbroadcast txns are in mempool (gzhao408) a7ebe48b94c5a9195c8eabd193204c499cb4bfdb [rpc] add unbroadcast info to mempool entries and getmempoolinfo (gzhao408) d16006960443c2efe37c896e46edae9dca86c57d [wallet] remove nLastResend logic (gzhao408) Pull request description: Followup to #18038 by amitiuttarwar which introduces the unbroadcast set: "a mechanism for the mempool to track locally submitted transactions" and decreases the frequency of rebroadcast from 10-15 minutes to 12-36 hours. This PR addresses some of the outstanding TODOs building on top of it: - remove `nLastResend` logic, which is used to ensure rebroadcast doesn't happen again if no new block has been mined (makes sense in 10-15 min period, but not necessary for 12-36 hour period). (#18038 [comment](https://github.com/bitcoin/bitcoin/pull/18038#discussion_r416826914)) - expose unbroadcast info via RPCs, for more informative queries and testing (#18038 [comment](https://github.com/bitcoin/bitcoin/pull/18038#discussion_r416837980)) - add sanity check to verify unbroadcast transactions still exist in mempool before rebroadcasting (#18038 [comment](https://github.com/bitcoin/bitcoin/pull/18038#discussion_r416861609)) ACKs for top commit: naumenkogs: Code review ACK 651f1d816f054cb9c637f8a99c9360bba381ef58 amitiuttarwar: ACK 651f1d816f054cb9c637f8a99c9360bba381ef58 🎉 MarcoFalke: Review ACK 651f1d816f054cb9c637f8a99c9360bba381ef58 Tree-SHA512: d5327e95ef39d44152b48df5c610502ae11c168f43dbbfb2885340c93d1ba9426eb3a5794573f5fc843502109cb3ffb63efa3f2db4f8f112efcde8f76d9a8845
110 lines
4.0 KiB
Python
Executable File
110 lines
4.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2017-2020 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Test that the mempool ensures transaction delivery by periodically sending
|
|
to peers until a GETDATA is received."""
|
|
|
|
import time
|
|
|
|
from test_framework.mininode import P2PTxInvStore
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import (
|
|
assert_equal,
|
|
create_confirmed_utxos,
|
|
)
|
|
|
|
|
|
class MempoolUnbroadcastTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.num_nodes = 2
|
|
|
|
def skip_test_if_missing_module(self):
|
|
self.skip_if_no_wallet()
|
|
|
|
def run_test(self):
|
|
self.test_broadcast()
|
|
self.test_txn_removal()
|
|
|
|
def test_broadcast(self):
|
|
self.log.info("Test that mempool reattempts delivery of locally submitted transaction")
|
|
node = self.nodes[0]
|
|
|
|
min_relay_fee = node.getnetworkinfo()["relayfee"]
|
|
utxos = create_confirmed_utxos(min_relay_fee, node, 10)
|
|
|
|
self.disconnect_nodes(0, 1)
|
|
|
|
self.log.info("Generate transactions that only node 0 knows about")
|
|
|
|
# generate a wallet txn
|
|
addr = node.getnewaddress()
|
|
wallet_tx_hsh = node.sendtoaddress(addr, 0.0001)
|
|
|
|
# generate a txn using sendrawtransaction
|
|
us0 = utxos.pop()
|
|
inputs = [{"txid": us0["txid"], "vout": us0["vout"]}]
|
|
outputs = {addr: 0.0001}
|
|
tx = node.createrawtransaction(inputs, outputs)
|
|
node.settxfee(min_relay_fee)
|
|
txF = node.fundrawtransaction(tx)
|
|
txFS = node.signrawtransactionwithwallet(txF["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
|
|
mempool = self.nodes[1].getrawmempool()
|
|
assert rpc_tx_hsh not in mempool
|
|
assert wallet_tx_hsh not in mempool
|
|
|
|
# ensure that unbroadcast txs are persisted to mempool.dat
|
|
self.restart_node(0)
|
|
|
|
self.log.info("Reconnect nodes & check if they are sent to node 1")
|
|
self.connect_nodes(0, 1)
|
|
|
|
# fast forward into the future & ensure that the second node has the txns
|
|
node.mockscheduler(15 * 60) # 15 min in seconds
|
|
self.sync_mempools(timeout=30)
|
|
mempool = self.nodes[1].getrawmempool()
|
|
assert rpc_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("Add another connection & ensure transactions aren't broadcast again")
|
|
|
|
conn = node.add_p2p_connection(P2PTxInvStore())
|
|
node.mockscheduler(15 * 60)
|
|
time.sleep(5)
|
|
assert_equal(len(conn.get_invs()), 0)
|
|
|
|
def test_txn_removal(self):
|
|
self.log.info("Test that transactions removed from mempool are removed from unbroadcast set")
|
|
node = self.nodes[0]
|
|
self.disconnect_nodes(0, 1)
|
|
node.disconnect_p2ps()
|
|
|
|
# since the node doesn't have any connections, it will not receive
|
|
# any GETDATAs & thus the transaction will remain in the unbroadcast set.
|
|
addr = node.getnewaddress()
|
|
txhsh = node.sendtoaddress(addr, 0.0001)
|
|
|
|
# check transaction was removed from unbroadcast set due to presence in
|
|
# a block
|
|
removal_reason = "Removed {} from set of unbroadcast txns before confirmation that txn was sent out".format(txhsh)
|
|
with node.assert_debug_log([removal_reason]):
|
|
node.generate(1)
|
|
|
|
if __name__ == "__main__":
|
|
MempoolUnbroadcastTest().main()
|