mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
be6a045b8c
9e1cb1adf1800efe429e348650931f2669b0d2c0 [trivial/doc] Fix comment type (Amiti Uttarwar)
8f30260a67166a6ab7c0f33f7ec1990d3c31761e [doc] Update unbroadcast description in RPC results (Amiti Uttarwar)
750456d6f29c63d57af05bfbdd6035bb9c965de2 [trivial] Remove misleading 'const' (Amiti Uttarwar)
fa32e676e5833a5c5fc735ef00c0a80f5fab7a2c [test] Manage node connections better in mempool persist test (Amiti Uttarwar)
1f94bb0c744a103b633c1051e8fbc01e612097dc [doc] Provide rationale for randomization in scheduling. (Amiti Uttarwar)
9c8a55d9cb0ec73f10b196e79b637aa601c0a6b7 [mempool] Don't throw expected error message when upgrading (Amiti Uttarwar)
ba5498318233ab81decbc585e9619d8ffe2df1b0 [test] Test that wallet transactions aren't rebroadcast before 12 hours (Amiti Uttarwar)
00d44a534b4e5ae249b8011360c6b0f7dc731581 [test] P2P connection behavior should meet expectations (Amiti Uttarwar)
bd093ca15de762fdaf0937a0877d17b0c2bce16e [test] updates to unbroadcast test (Amiti Uttarwar)
dab298d9ab5a5a41685f437db9081fa7b395fa73 [docs] add release notes (Amiti Uttarwar)
Pull request description:
This PR is a follow up to #18038 which introduced the idea of an unbroadcast set & focuses mostly on documentation updates and test fixes. One small functionality update to not throw an expected error in `LoadMempool` when you upgrade software versions.
#18895 is another follow up to that addresses other functionality updates.
Background context:
The unbroadcast set is a mechanism for the mempool to track locally submitted transactions (via wallet or RPC). The node does a best-effort of delivering the transactions to the network via retries every 10-15 minutes until either a `GETDATA` is received or the transaction is removed from the mempool.
ACKs for top commit:
MarcoFalke:
ACK 9e1cb1adf1 👁
gzhao408:
ACK [`9e1cb1a`](9e1cb1adf1
)
Tree-SHA512: 0cd51c4ca368b9dce92d50d73ec6e9df278a259e609eef2858f24cb8595ad07acc3db781d9eb0c351715f18fca5a2b4526838981fdb34a522427e9dc868bdaa6
112 lines
4.1 KiB
Python
Executable File
112 lines
4.1 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,
|
|
)
|
|
|
|
MAX_INITIAL_BROADCAST_DELAY = 15 * 60 # 15 minutes in seconds
|
|
|
|
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(MAX_INITIAL_BROADCAST_DELAY)
|
|
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(MAX_INITIAL_BROADCAST_DELAY)
|
|
time.sleep(2) # allow sufficient time for possibility of broadcast
|
|
assert_equal(len(conn.get_invs()), 0)
|
|
|
|
self.disconnect_nodes(0, 1)
|
|
node.disconnect_p2ps()
|
|
|
|
def test_txn_removal(self):
|
|
self.log.info("Test that transactions removed from mempool are removed from unbroadcast set")
|
|
node = self.nodes[0]
|
|
|
|
# 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()
|