From 1f1fdac7dc3e0f63fffab7e23231237e128e2cf1 Mon Sep 17 00:00:00 2001 From: PastaClaw Date: Mon, 16 Nov 2026 00:20:30 -0600 Subject: [PATCH] Revert "Merge dashpay/dash#8156: test: shorten the default functional suite" Restore the default functional suite coverage and runtime behavior until the issues in the shortened suite can be reviewed and addressed separately. Co-Authored-By: Claude Code --- test/functional/feature_asset_locks.py | 736 +++++++++++++++++- test/functional/feature_asset_locks_v24.py | 625 --------------- .../feature_dip3_deterministicmns.py | 8 +- .../feature_dip4_coinbasemerkleroots.py | 4 - test/functional/feature_governance.py | 113 ++- test/functional/feature_governance_cl.py | 12 +- test/functional/feature_governance_pruned.py | 108 --- .../feature_governance_trigger_voting.py | 31 +- test/functional/feature_llmq_chainlocks.py | 13 +- test/functional/feature_llmq_connections.py | 12 +- test/functional/feature_llmq_data_recovery.py | 14 +- .../functional/feature_llmq_is_retroactive.py | 1 + test/functional/feature_llmq_signing.py | 20 +- test/functional/feature_llmq_simplepose.py | 28 +- .../feature_llmq_simplepose_capabilities.py | 18 +- test/functional/feature_llmq_singlenode.py | 18 +- test/functional/feature_protx_version.py | 8 +- test/functional/feature_stats.py | 1 - test/functional/interface_zmq_dash.py | 17 +- .../mining_getblocktemplate_longpoll.py | 23 +- ...ining_getblocktemplate_longpoll_mempool.py | 42 - test/functional/p2p_dstx.py | 8 +- test/functional/p2p_platform_ban.py | 12 +- test/functional/p2p_quorum_data.py | 43 +- test/functional/rpc_mnauth.py | 17 +- test/functional/rpc_netinfo.py | 2 + test/functional/rpc_quorum.py | 1 + test/functional/rpc_verifychainlock.py | 1 + test/functional/rpc_verifyislock.py | 4 + test/functional/test_framework/asset_locks.py | 210 ----- test/functional/test_framework/simplepose.py | 22 +- test/functional/test_runner.py | 50 +- test/functional/wallet_dust_protection.py | 41 +- test/functional/wallet_upgradetohd.py | 13 +- 34 files changed, 1106 insertions(+), 1170 deletions(-) delete mode 100755 test/functional/feature_asset_locks_v24.py delete mode 100755 test/functional/feature_governance_pruned.py delete mode 100755 test/functional/mining_getblocktemplate_longpoll_mempool.py delete mode 100644 test/functional/test_framework/asset_locks.py diff --git a/test/functional/feature_asset_locks.py b/test/functional/feature_asset_locks.py index 66ea125c661c..c72f2f09c7b0 100755 --- a/test/functional/feature_asset_locks.py +++ b/test/functional/feature_asset_locks.py @@ -4,54 +4,191 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -"""Test Asset Lock and Asset Unlock transactions through the v24 fork. - -Version 2 asset unlocks, non-standard asset locks and crash replay are in -feature_asset_locks_v24.py. -""" - import copy +import http.client +import struct +import subprocess from decimal import Decimal from io import BytesIO -from test_framework.asset_locks import ( - AssetLocksMixin, - HEIGHT_DIFF_EXPIRING, - blocks_in_one_day, - llmq_type_test, - tiny_amount, -) from test_framework.blocktools import ( create_block, create_coinbase, ) from test_framework.authproxy import JSONRPCException from test_framework.messages import ( + CAssetLockTx, CAssetUnlockTx, + CCoinJoinBroadcastTx, COIN, + COutPoint, + CTransaction, + CTxIn, + CTxOut, + MSG_ASSET_UNLOCK, + msg_dstx, msg_tx, tx_from_hex, + hash256, + ser_string, ) from test_framework.p2p import P2PInterface -from test_framework.script import hash160 -from test_framework.script_util import key_to_p2pkh_script +from test_framework.script import ( + CScript, + hash160, + OP_RETURN, +) +from test_framework.script_util import ( + key_to_p2pk_script, + key_to_p2pkh_script, +) from test_framework.test_framework import DashTestFramework from test_framework.util import ( assert_equal, assert_greater_than, assert_greater_than_or_equal, + assert_raises, assert_raises_rpc_error, softfork_active, ) from test_framework.segwit_addr import encode_platform_p2pkh from test_framework.wallet_util import generate_keypair +llmq_type_test = 106 # LLMQType::LLMQ_TEST_PLATFORM +MNEHF_SIGNAL_TX_TYPE = 7 # TRANSACTION_MNHF_SIGNAL +ASSET_UNLOCK_TX_TYPE = 9 # TRANSACTION_ASSET_UNLOCK +tiny_amount = int(Decimal("0.0007") * COIN) +blocks_in_one_day = 100 +HEIGHT_DIFF_EXPIRING = 48 + +class InvListener(P2PInterface): + def __init__(self): + super().__init__() + self.asset_unlock_invs = [] + + def on_inv(self, message): + for i in message.inv: + if i.type == MSG_ASSET_UNLOCK: + self.asset_unlock_invs.append(i.hash) + + +class AssetLocksTest(DashTestFramework): + def add_options(self, parser): + self.add_wallet_options(parser) -class AssetLocksTest(AssetLocksMixin, DashTestFramework): def set_test_params(self): - self.set_asset_locks_test_params() + self.set_dash_test_params(2, 0, [[ + "-whitelist=127.0.0.1", + "-llmqtestinstantsenddip0024=llmq_test_instantsend", + "-acceptnonstdtxn=1", + ]] * 2, evo_count=2) self.mn_rr_height = 560 + def skip_test_if_missing_module(self): + self.skip_if_no_wallet() + + def create_assetlock(self, coin, amount, pubkey, version=1): + node_wallet = self.nodes[0] + + + coins = coin if isinstance(coin, list) else [coin] + inputs = [CTxIn(COutPoint(int(c["txid"], 16), c["vout"])) for c in coins] + + credit_outputs = [] + tmp_amount = amount + if tmp_amount > COIN: + tmp_amount -= COIN + credit_outputs.append(CTxOut(COIN, key_to_p2pkh_script(pubkey))) + credit_outputs.append(CTxOut(tmp_amount, key_to_p2pkh_script(pubkey))) + + lockTx_payload = CAssetLockTx(version, credit_outputs) + + remaining = sum(int(COIN * c['amount']) for c in coins) - tiny_amount - amount + + tx_output_ret = CTxOut(amount, CScript([OP_RETURN, b""])) + tx_output = CTxOut(remaining, key_to_p2pk_script(pubkey)) + + lock_tx = CTransaction() + lock_tx.vin = inputs + lock_tx.vout = [tx_output, tx_output_ret] if remaining > 0 else [tx_output_ret] + lock_tx.nVersion = 3 + lock_tx.nType = 8 # asset lock type + lock_tx.vExtraPayload = lockTx_payload.serialize() + + lock_tx = node_wallet.signrawtransactionwithwallet(lock_tx.serialize().hex()) + return tx_from_hex(lock_tx["hex"]) + + + def create_assetunlock_request_id(self, index): + # request ID = sha256("plwdtx", index) + request_id_buf = ser_string(b"plwdtx") + struct.pack(" 0: + self.log.info(f"Generating batch of blocks {count} left") + batch = min(50, count) + count -= batch + self.bump_mocktime(10 * 60 + 1) + self.generate(self.nodes[1], batch, sync_fun=sync_fun) + + # This functional test intentionally setup only 2 MN and only 2 Evo nodes + # to ensure that corner case of quorum with minimum amount of nodes as possible + # does not cause any issues in Dash Core + def mine_quorum_2_nodes(self): + self.mine_quorum(llmq_type_name='llmq_test_platform', expected_members=2, expected_connections=1, expected_contributions=2, expected_commitments=2, llmq_type=106) + def run_test(self): node_wallet = self.nodes[0] node = self.nodes[1] @@ -161,6 +351,10 @@ def run_test(self): self.test_withdrawals_fork(node_wallet, node, pubkey) self.test_asset_locks_v2_pre_v24(node_wallet, node, pubkey) self.test_v24_fork(node_wallet, node, pubkey) + self.test_asset_unlock_v2(node_wallet, node, pubkey) + self.test_non_standard(node_wallet, node, pubkey) + self.test_replay_after_crash(node_wallet, node, pubkey) + def test_asset_locks(self, node_wallet, node, pubkey): self.log.info("Testing asset lock...") @@ -227,6 +421,7 @@ def test_asset_locks(self, node_wallet, node, pubkey): self.validate_credit_pool_balance(locked_1) + def test_asset_unlocks(self, node_wallet, node, pubkey): self.log.info("Testing asset unlock...") @@ -300,6 +495,8 @@ def test_asset_unlocks(self, node_wallet, node, pubkey): self.check_mempool_size() self.validate_credit_pool_balance(locked) self.generate(node, 1) + assert_equal(rawtx["instantlock"], False) + assert_equal(rawtx["chainlock"], False) rawtx = node.getrawtransaction(txid, 1) assert_equal(rawtx["confirmations"], 1) self.validate_credit_pool_balance(locked - COIN) @@ -358,6 +555,7 @@ def test_asset_unlocks(self, node_wallet, node, pubkey): self.log.info("Forcibly mine asset_unlock_tx_duplicate_index and ensure block is invalid") self.create_and_check_block([asset_unlock_tx_duplicate_index], expected_error = "bad-assetunlock-duplicated-index") + def test_withdrawal_limits(self, node_wallet, node, pubkey): self.log.info("Testing withdrawal limits before v22 'withdrawal fork'...") assert not softfork_active(node_wallet, 'withdrawals') @@ -515,6 +713,7 @@ def test_withdrawal_limits(self, node_wallet, node, pubkey): self.check_mempool_size() assert not softfork_active(node_wallet, 'withdrawals') + def test_mn_rr(self, node_wallet, node, pubkey): self.log.info("Activate mn_rr...") locked = self.get_credit_pool_balance() @@ -589,6 +788,23 @@ def test_v24_fork(self, node_wallet, node, pubkey): self.test_asset_locks_v2(node_wallet, node, pubkey) + asset_unlock_tx, asset_unlock_tx_payload, quorumHash_str = self.create_assetunlock_for_oldest_quorum(601, COIN, pubkey) + self.log.info("Check that Asset Unlock tx is valid for current quorum") + self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}}) + + assert quorumHash_str in node_wallet.quorum('list')['llmq_test_platform'] + self.log.info("Generate one more quorum to make signing quorum inactive but still valid") + self.mine_quorum_2_nodes() + assert quorumHash_str not in node_wallet.quorum('list')['llmq_test_platform'] + + + assert asset_unlock_tx_payload.requestedHeight + HEIGHT_DIFF_EXPIRING > node_wallet.getblockcount() + self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}}) + + self.log.info("Generate one more quorum after which signing quorum becomes too old") + self.mine_quorum_2_nodes() + self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': False, 'reject-reason': 'bad-assetunlock-too-old-quorum'}) + self.test_admissible_asset_unlock_ancestor_package(node_wallet, pubkey) self.log.info("The v24 limit is 20% of the balance one window ago, at least 2000, net of the window's drop") @@ -668,6 +884,20 @@ def check_v24_unlock_limit(self, node): assert_raises_rpc_error(-8, "Block height out of range", node.getcreditpoolinfo, -1) return expected_limit + def create_asset_unlock_child(self, node_wallet, asset_unlock_tx, asset_unlock_txid): + child_value = Decimal(asset_unlock_tx.vout[0].nValue - tiny_amount) / COIN + child_hex = node_wallet.createrawtransaction( + [{'txid': asset_unlock_txid, 'vout': 0}], + {node_wallet.getnewaddress(): child_value}) + signed_child = node_wallet.signrawtransactionwithwallet(child_hex) + assert signed_child['complete'] + child_txid = node_wallet.sendrawtransaction(signed_child['hex']) + + # Ensure package selection considers the child before its Asset Unlock + # ancestor is considered on its own. + node_wallet.prioritisetransaction(child_txid, COIN) + return child_txid + def test_admissible_asset_unlock_ancestor_package(self, node_wallet, pubkey): self.log.info("Test an admissible Asset Unlock ancestor package") asset_unlock_tx = self.create_assetunlock(619, COIN, pubkey) @@ -691,6 +921,388 @@ def test_asset_unlock_ancestor_package(self, node_wallet, asset_unlock_tx, asset assert asset_unlock_txid not in template_txids assert child_txid not in template_txids + def test_asset_unlock_v2(self, node_wallet, node, pubkey): + self.log.info("Testing v2 asset unlocks with stable txids...") + assert softfork_active(node_wallet, 'v24') + self.log.info("Enable InstantSend: version 2 unlocks are locked once they are minable within the limit") + node_wallet.sporkupdate("SPORK_2_INSTANTSEND_ENABLED", 0) + self.wait_for_sporks_same() + + # The withdrawal window is exhausted by test_v24_fork, so v2 instances created here stay + # unminable in the mempool until the window clears + index = 800 + listener = node_wallet.add_p2p_connection(InvListener()) + # A peer at the current protocol version supplies the first instance; refreshes of the + # withdrawal must still be announced to it later + sender = node_wallet.add_p2p_connection(InvListener()) + unlock_a = self.create_assetunlock(index, COIN, pubkey, version=2) + stable_txid = self.get_v2_txid(unlock_a) + instance_a = unlock_a.rehash() + assert stable_txid != instance_a + + sender.send_and_ping(msg_tx(unlock_a)) + self.wait_until(lambda: stable_txid in node_wallet.getrawmempool()) + self.sync_mempools() + rpc_tx = node_wallet.getrawtransaction(stable_txid, 1) + assert_equal(rpc_tx['txid'], stable_txid) + assert_equal(rpc_tx['instanceHash'], instance_a) + + self.log.info("The v2 unlock is announced by instance hash") + self.wait_until(lambda: int(instance_a, 16) in listener.asset_unlock_invs) + + self.log.info("Pending withdrawals exceed the limit, so the unlock is not locked while an ordinary tx is") + pending = node_wallet.getmempoolinfo()['pendingassetunlocks'] + # the leftover over-limit unlocks of test_v24_fork exceed a whole window's allowed drop + info = node_wallet.getcreditpoolinfo() + allowed_drop = max(info['window']['balance'] * 20 / 100, 2000) + assert_greater_than(pending, allowed_drop) + assert_greater_than(pending, info['currentlimit']) + is_txid = node_wallet.sendtoaddress(node_wallet.getnewaddress(), 1) + self.wait_for_instantlock(is_txid) + assert_equal(node_wallet.getrawtransaction(stable_txid, 1)['instantlock'], False) + assert_equal(node_wallet.getassetunlockstatuses([str(index)])[0], {'index': index, 'status': 'mempooled', 'instantlock': False}) + + self.log.info("A second withdrawal refused on the limit is retried automatically once the window clears") + retry_index = 801 + unlock_retry = self.create_assetunlock(retry_index, COIN, pubkey, version=2) + retry_txid = self.get_v2_txid(unlock_retry) + assert_equal(self.send_tx_simple(unlock_retry), retry_txid) + self.sync_mempools() + assert_equal(node_wallet.getrawtransaction(retry_txid, 1)['instantlock'], False) + + self.log.info("Spend the unmined v2 unlock by its stable txid") + child_value = Decimal(unlock_a.vout[0].nValue - tiny_amount) / COIN + child_hex = node_wallet.createrawtransaction( + [{'txid': stable_txid, 'vout': 0}], + {node_wallet.getnewaddress(): child_value}) + signed_child = node_wallet.signrawtransactionwithwallet(child_hex) + assert signed_child['complete'] + child_txid = node_wallet.sendrawtransaction(signed_child['hex']) + self.sync_mempools() + assert child_txid in node_wallet.getrawmempool() + + def child_output(): + return next(u for u in node_wallet.listunspent(0) if u['txid'] == child_txid) + self.log.info("Without a lock on the withdrawal the wallet does not trust the child's output") + assert_equal(child_output()['safe'], False) + + self.log.info("A fresher re-signed instance refreshes the entry in place; same txid, child untouched") + self.generate(node, 1) + unlock_a2 = self.create_assetunlock(index, COIN, pubkey, version=2) + assert_equal(self.get_v2_txid(unlock_a2), stable_txid) + instance_a2 = unlock_a2.rehash() + assert instance_a2 != instance_a + assert_equal(self.send_tx_simple(unlock_a2), stable_txid) + self.sync_unlock_instance(stable_txid, instance_a2) + mempool = node_wallet.getrawmempool() + assert stable_txid in mempool + assert child_txid in mempool + self.log.info("The refresh is announced under its own instance hash, including to the peer that sent the first instance") + self.wait_until(lambda: int(instance_a2, 16) in listener.asset_unlock_invs) + self.wait_until(lambda: int(instance_a2, 16) in sender.asset_unlock_invs) + assert int(instance_a, 16) not in sender.asset_unlock_invs + + self.log.info("A stale instance does not refresh a fresher one") + assert_raises_rpc_error(-26, 'assetunlock-stale-instance', self.send_tx_simple, unlock_a) + + self.log.info("A stale instance in a package is rejected by the refresh path; the fresher held instance stays") + stale_package_child_hex = node_wallet.createrawtransaction( + [{'txid': stable_txid, 'vout': 0}], + {node_wallet.getnewaddress(): child_value}) + signed_stale_package_child = node_wallet.signrawtransactionwithwallet(stale_package_child_hex) + assert signed_stale_package_child['complete'] + assert_raises_rpc_error(-26, f'{stable_txid} failed: assetunlock-stale-instance', node_wallet.submitpackage, + [unlock_a.serialize().hex(), signed_stale_package_child['hex']]) + assert_equal(node_wallet.getrawtransaction(stable_txid, 1)['instanceHash'], instance_a2) + assert child_txid in node_wallet.getrawmempool() + + self.log.info("Package test acceptance treats the held withdrawal as already in the mempool") + # A multi-transaction testmempoolaccept must not route the mempooled unlock through the + # in-place refresh path: that used to leave the package feerate accounting unfilled and + # abort the node. Refreshes are only admitted through single-transaction submission. + funded = node_wallet.fundrawtransaction(node_wallet.createrawtransaction([], {node_wallet.getnewaddress(): 1})) + signed_sibling = node_wallet.signrawtransactionwithwallet(funded['hex']) + assert signed_sibling['complete'] + package_result = node_wallet.testmempoolaccept([unlock_a2.serialize().hex(), signed_sibling['hex']]) + assert_equal(package_result[0]['txid'], stable_txid) + assert_equal(package_result[0]['allowed'], False) + assert_equal(package_result[0]['reject-reason'], 'txn-already-in-mempool') + + self.log.info("Expire the v2 instance; it and its child must survive in the mempool") + self.generate_batch(HEIGHT_DIFF_EXPIRING + 1) + mempool = node_wallet.getrawmempool() + assert stable_txid in mempool + assert child_txid in mempool + assert retry_txid in mempool + + self.log.info("A node without the expired instances admits them and the child from a peer") + expired_hexes = [node_wallet.getrawtransaction(txid) for txid in (stable_txid, retry_txid, child_txid)] + # Stopping dumps node's mempool, which the -persistmempool=0 run neither loads nor overwrites + self.restart_node(1, self.extra_args[1] + ["-persistmempool=0"]) + assert stable_txid not in node.getrawmempool() + expired_peer = node.add_p2p_connection(P2PInterface()) + with node.assert_debug_log(expected_msgs=[], unexpected_msgs=["Misbehaving"]): + for tx_hex in expired_hexes: + expired_peer.send_and_ping(msg_tx(tx_from_hex(tx_hex))) + mempool = node.getrawmempool() + assert stable_txid in mempool + assert retry_txid in mempool + assert child_txid in mempool + + self.log.info("An expired instance must still carry a signature valid at its requestedHeight") + forged = tx_from_hex(expired_hexes[0]) + forged_payload = CAssetUnlockTx() + forged_payload.deserialize(BytesIO(forged.vExtraPayload)) + forged_payload.index = 810 + forged.vExtraPayload = forged_payload.serialize() + forged_peer = node.add_p2p_connection(P2PInterface()) + with node.assert_debug_log(expected_msgs=["bad-assetunlock-not-verified", "Misbehaving: peer=", "(0 -> 100)"]): + forged_peer.send_and_ping(msg_tx(forged)) + node.disconnect_p2ps() + + self.log.info("A requestedHeight overflowing the height window is rejected as too late") + overflow_unlock = self.create_assetunlock(812, COIN, pubkey, version=2, requested_height=2**32 - HEIGHT_DIFF_EXPIRING) + assert_equal(node.testmempoolaccept([overflow_unlock.serialize().hex()])[0]['reject-reason'], 'bad-assetunlock-too-late') + + self.log.info("An expired instance signed by a quorum mined after its requestedHeight is admitted") + late_index = 811 + late_quorum = self.mninfo[0].get_node(self).quorum("selectquorum", llmq_type_test, self.create_assetunlock_request_id(late_index))["quorumHash"] + late_quorum_mined_height = node.getblock(node.quorum("info", llmq_type_test, late_quorum)["minedBlock"])["height"] + late_quorum_unlock = self.create_assetunlock(late_index, COIN, pubkey, version=2, requested_height=late_quorum_mined_height - 1) + blocks_to_expiry = late_quorum_mined_height - 1 + HEIGHT_DIFF_EXPIRING - node.getblockcount() + if blocks_to_expiry > 0: + # node is still disconnected from node_wallet after its restart above + self.generate(node, blocks_to_expiry, sync_fun=self.no_op) + assert_equal(node.testmempoolaccept([late_quorum_unlock.serialize().hex()])[0]['allowed'], True) + + self.log.info("The expired instances and the child survive a restart") + self.restart_node(1, self.extra_args[1]) + mempool = node.getrawmempool() + assert stable_txid in mempool + assert retry_txid in mempool + assert child_txid in mempool + self.connect_nodes(1, 0) + self.sync_all() + + self.log.info("Flush leftover withdrawals from earlier phases and clear the window; the expired instance keeps waiting for a re-sign") + # Pending unlocks from the limit tests would otherwise consume the cleared window and + # crowd this test's withdrawal out of the block. Mine until each of them is either mined + # or expired and evicted; the expired instance under test cannot be mined and stays. + + def other_unlocks_pending(): + self.sync_mempools() + return any(txid not in (stable_txid, retry_txid) and node_wallet.getrawtransaction(txid, 1)['type'] == ASSET_UNLOCK_TX_TYPE + for txid in node_wallet.getrawmempool()) + flushed = 0 + while other_unlocks_pending(): + self.generate(node, 1) + flushed += 1 + assert flushed <= 2 * blocks_in_one_day, "leftover withdrawals never left the mempool" + self.generate_batch(101) + mempool = node_wallet.getrawmempool() + assert stable_txid in mempool + assert child_txid in mempool + self.log.info("A whole window later the allowance has regenerated to at least the 2000 DASH floor") + assert_greater_than_or_equal(node_wallet.getcreditpoolinfo()['currentlimit'], 2000) + + self.log.info("Both expired instances fit the cleared limit but are not minable, so neither is locked") + assert_equal(node_wallet.getmempoolinfo()['pendingassetunlocks'], 2 * Decimal(unlock_a.vout[0].nValue + tiny_amount) / COIN) + assert_equal(node_wallet.getrawtransaction(stable_txid, 1)['instantlock'], False) + assert_equal(node_wallet.getrawtransaction(retry_txid, 1)['instantlock'], False) + + self.log.info("Refreshing the second withdrawal gets it locked: the per-block retry re-evaluates it against the cleared limit") + unlock_retry_b = self.create_assetunlock(retry_index, COIN, pubkey, version=2) + assert_equal(self.send_tx_simple(unlock_retry_b), retry_txid) + self.sync_unlock_instance(retry_txid, unlock_retry_b.rehash()) + self.wait_for_instantlock(retry_txid) + self.generate(node, 1) + assert retry_txid not in node_wallet.getrawmempool() + + self.log.info("Refresh the expired instance with a fresh re-sign: minable and within the limit, it gets locked") + unlock_b = self.create_assetunlock(index, COIN, pubkey, version=2) + assert_equal(self.get_v2_txid(unlock_b), stable_txid) + assert_equal(self.send_tx_simple(unlock_b), stable_txid) + self.sync_unlock_instance(stable_txid, unlock_b.rehash()) + self.wait_for_instantlock(stable_txid) + assert_equal(node_wallet.getassetunlockstatuses([str(index)])[0], {'index': index, 'status': 'mempooled', 'instantlock': True}) + self.log.info("The lock pins the withdrawal index as the unlock's single input") + islock = node_wallet.getislocks([stable_txid])[0] + assert_equal(islock['inputs'], [{'txid': self.create_assetunlock_request_id(index), 'vout': 0}]) + self.log.info("The child is an ordinary spend of a locked parent: it gets locked and the wallet trusts it") + self.wait_for_instantlock(child_txid) + assert_equal(child_output()['safe'], True) + + self.log.info("A peer relaying an older instance of the locked withdrawal does not strip the locks") + # The rejected instance shares the txid of the locked one still held in the mempool + stale_peer = node_wallet.add_p2p_connection(P2PInterface()) + with node_wallet.assert_debug_log([f"{stable_txid} from peer=", "was not accepted"]): + stale_peer.send_and_ping(msg_tx(unlock_a2)) + assert_equal(node_wallet.getrawtransaction(stable_txid, 1)['instanceHash'], unlock_b.rehash()) + assert_equal(node_wallet.getrawtransaction(stable_txid, 1)['instantlock'], True) + assert_equal(node_wallet.getrawtransaction(child_txid, 1)['instantlock'], True) + + self.log.info("Mine the withdrawal with its child") + tip_hash = self.generate(node, 1)[0] + block = node_wallet.getblock(tip_hash, 2) + mined_txids = [t['txid'] for t in block['tx']] + assert stable_txid in mined_txids + assert child_txid in mined_txids + # The coinbase commits to the mined instance's hash; a single leaf is its own merkle root + assert_equal(block['cbTx']['merkleRootAssetUnlocks'], unlock_b.rehash()) + assert_equal(node_wallet.getassetunlockstatuses([str(index)])[0], {'index': index, 'status': 'mined'}) + child_rpc = node_wallet.getrawtransaction(child_txid, 1) + assert_equal(child_rpc['vin'][0]['txid'], stable_txid) + assert_equal(node_wallet.getrawtransaction(stable_txid, 1)['instantlock'], True) + + self.log.info("At most one instance of a withdrawal index is held: a version 1 instance signed one block earlier is the claimant") + cross_index = 803 + tip_height = node_wallet.getblockcount() + unlock_v1 = self.create_assetunlock(cross_index, COIN, pubkey, version=1, requested_height=tip_height - 1) + v1_txid = self.send_tx_simple(unlock_v1) + self.sync_mempools() + + self.log.info("A version 2 instance signed at the same height is stale: rejected before its signature is verified") + unlock_v2_stale = self.create_assetunlock(cross_index, COIN, pubkey, version=2, requested_height=tip_height - 1) + stale_result = node_wallet.testmempoolaccept([unlock_v2_stale.serialize().hex()])[0] + assert_equal(stale_result['txid'], self.get_v2_txid(unlock_v2_stale)) + assert_equal(stale_result['allowed'], False) + assert_equal(stale_result['reject-reason'], 'assetunlock-stale-instance') + assert v1_txid in node_wallet.getrawmempool() + + unlock_v2_fresh = self.create_assetunlock(cross_index, COIN, pubkey, version=2, requested_height=tip_height) + cross_txid = self.get_v2_txid(unlock_v2_fresh) + self.log.info("A package cannot replace an unlock while spending the evicted claimant") + package_child_hex = node_wallet.createrawtransaction( + [{'txid': v1_txid, 'vout': 0}, {'txid': cross_txid, 'vout': 0}], + {node_wallet.getnewaddress(): Decimal(unlock_v1.vout[0].nValue + unlock_v2_fresh.vout[0].nValue - tiny_amount) / COIN}) + fresh_prevout = {'txid': cross_txid, 'vout': 0, 'scriptPubKey': unlock_v2_fresh.vout[0].scriptPubKey.hex(), + 'amount': Decimal(unlock_v2_fresh.vout[0].nValue) / COIN} + signed_package_child = node_wallet.signrawtransactionwithwallet(package_child_hex, [fresh_prevout]) + assert signed_package_child['complete'] + assert_raises_rpc_error(-25, 'assetunlock-conflicting-package', node_wallet.submitpackage, + [unlock_v1.serialize().hex(), unlock_v2_fresh.serialize().hex(), signed_package_child['hex']]) + assert v1_txid in node_wallet.getrawmempool() + assert cross_txid not in node_wallet.getrawmempool() + + self.log.info("Package test acceptance predicts that rejection rather than validating the child against the evicted claimant") + evicted_child_hex = node_wallet.createrawtransaction( + [{'txid': v1_txid, 'vout': 0}], + {node_wallet.getnewaddress(): Decimal(unlock_v1.vout[0].nValue - tiny_amount) / COIN}) + signed_evicted_child = node_wallet.signrawtransactionwithwallet(evicted_child_hex) + assert signed_evicted_child['complete'] + test_result = node_wallet.testmempoolaccept([unlock_v2_fresh.serialize().hex(), signed_evicted_child['hex']]) + assert_equal([r['txid'] for r in test_result], [cross_txid, node_wallet.decoderawtransaction(signed_evicted_child['hex'])['txid']]) + for r in test_result: + assert_equal(r['package-error'], 'assetunlock-conflicting-package') + assert 'allowed' not in r + assert v1_txid in node_wallet.getrawmempool() + assert cross_txid not in node_wallet.getrawmempool() + + self.log.info("A version 2 unlock wrapped in a dstx message goes through DSTX validation and is dropped") + dstx_peer = node_wallet.add_p2p_connection(P2PInterface()) + wrapped = CCoinJoinBroadcastTx(tx=unlock_v2_fresh, m_protxHash=1, vchSig=b"\x01" * 96, sigTime=self.mocktime) + with node_wallet.assert_debug_log(["Invalid DSTX structure", "invalid dstx"]): + dstx_peer.send_and_ping(msg_dstx(wrapped)) + assert cross_txid not in node_wallet.getrawmempool() + assert v1_txid in node_wallet.getrawmempool() + + self.log.info("Signed one block later, the version 2 instance is fresher: it replaces the version 1 claimant and gets locked") + assert_equal(self.send_tx_simple(unlock_v2_fresh), cross_txid) + self.sync_mempools() + mempool = node_wallet.getrawmempool() + assert cross_txid in mempool + assert v1_txid not in mempool + assert_equal(node_wallet.getmempoolinfo()['pendingassetunlocks'], Decimal(unlock_v2_fresh.vout[0].nValue + tiny_amount) / COIN) + self.wait_for_instantlock(cross_txid) + assert_equal(node_wallet.getassetunlockstatuses([str(cross_index)])[0], {'index': cross_index, 'status': 'mempooled', 'instantlock': True}) + tip_hash = self.generate(node, 1)[0] + assert cross_txid in node_wallet.getblock(tip_hash)['tx'] + + self.log.info("A rejected instance does not blacklist the txid shared by every instance of its withdrawal") + # The node does not hold this withdrawal yet. An instance with a tampered requestedHeight + # fails validation but carries the txid of the valid one, which a child already spends. + orphan_index = 804 + unlock_valid = self.create_assetunlock(orphan_index, COIN, pubkey, version=2) + parent_txid = self.get_v2_txid(unlock_valid) + tampered_payload = CAssetUnlockTx() + tampered_payload.deserialize(BytesIO(unlock_valid.vExtraPayload)) + tampered_payload.requestedHeight -= 1 + unlock_tampered = copy.deepcopy(unlock_valid) + unlock_tampered.vExtraPayload = tampered_payload.serialize() + assert_equal(self.get_v2_txid(unlock_tampered), parent_txid) + assert unlock_tampered.rehash() != unlock_valid.rehash() + + parent_value = unlock_valid.vout[0].nValue + orphan_child_hex = node_wallet.createrawtransaction( + [{'txid': parent_txid, 'vout': 0}], + {node_wallet.getnewaddress(): Decimal(parent_value - tiny_amount) / COIN}) + parent_prevout = {'txid': parent_txid, 'vout': 0, 'scriptPubKey': unlock_valid.vout[0].scriptPubKey.hex(), + 'amount': Decimal(parent_value) / COIN} + signed_orphan_child = node_wallet.signrawtransactionwithwallet(orphan_child_hex, [parent_prevout]) + assert signed_orphan_child['complete'] + orphan_child = tx_from_hex(signed_orphan_child['hex']) + orphan_child_txid = orphan_child.rehash() + + relay_peer = node_wallet.add_p2p_connection(P2PInterface()) + with node_wallet.assert_debug_log([f"{parent_txid} from peer=", "was not accepted"]): + relay_peer.send_and_ping(msg_tx(unlock_tampered)) + assert parent_txid not in node_wallet.getrawmempool() + + self.log.info("A child spending the withdrawal is kept as an orphan and accepted with its valid parent") + with node_wallet.assert_debug_log(expected_msgs=[], unexpected_msgs=["not keeping orphan with rejected parents"]): + relay_peer.send_and_ping(msg_tx(orphan_child)) + assert orphan_child_txid not in node_wallet.getrawmempool() + relay_peer.send_and_ping(msg_tx(unlock_valid)) + mempool = node_wallet.getrawmempool() + assert parent_txid in mempool + assert orphan_child_txid in mempool + self.wait_for_instantlock(parent_txid, orphan_child_txid) + tip_hash = self.generate(node, 1)[0] + mined_txids = node_wallet.getblock(tip_hash)['tx'] + assert parent_txid in mined_txids + assert orphan_child_txid in mined_txids + + self.log.info("A peer relaying an older instance of an unlocked withdrawal does not keep it from being locked later") + # A pending withdrawal over the credit pool limit keeps this one from being locked until it + # expires; the per-block retry must then lock it without another re-sign + tip_height = node_wallet.getblockcount() + blocker = self.create_assetunlock(805, 4001 * COIN, pubkey, version=1, + requested_height=tip_height - HEIGHT_DIFF_EXPIRING + 2) + blocker_txid = self.send_tx_simple(blocker) + unlock_old = self.create_assetunlock(806, COIN, pubkey, version=2) + retry_lock_txid = self.get_v2_txid(unlock_old) + assert_equal(self.send_tx_simple(unlock_old), retry_lock_txid) + self.sync_mempools() + # Empty blocks keep the withdrawal unmined while the blocker is pending + self.generateblock(node, node_wallet.getnewaddress(), []) + unlock_new = self.create_assetunlock(806, COIN, pubkey, version=2) + assert_equal(self.send_tx_simple(unlock_new), retry_lock_txid) + self.sync_unlock_instance(retry_lock_txid, unlock_new.rehash()) + assert blocker_txid in node_wallet.getrawmempool() + assert_equal(node_wallet.getrawtransaction(retry_lock_txid, 1)['instantlock'], False) + + for mn in self.mninfo: + mn_node = mn.get_node(self) + with mn_node.assert_debug_log([f"{retry_lock_txid} from peer=", "assetunlock-stale-instance"]): + mn_node.add_p2p_connection(P2PInterface()).send_and_ping(msg_tx(unlock_old)) + mn_node.disconnect_p2ps() + + self.log.info("Once the blocking withdrawal expires, the per-block retry locks the unlock") + for _ in range(3): + if blocker_txid not in node_wallet.getrawmempool(): + break + self.generateblock(node, node_wallet.getnewaddress(), []) + assert blocker_txid not in node_wallet.getrawmempool() + assert retry_lock_txid in node_wallet.getrawmempool() + self.wait_for_instantlock(retry_lock_txid) + tip_hash = self.generate(node, 1)[0] + assert retry_lock_txid in node_wallet.getblock(tip_hash)['tx'] + + node_wallet.disconnect_p2ps() + self.set_sporks() + self.mempool_size = node_wallet.getmempoolinfo()['size'] + self.check_mempool_size() + def test_asset_locks_v2_pre_v24(self, node_wallet, node, pubkey): self.log.info("Testing asset lock v2 rejection before v24 activation...") assert not softfork_active(node_wallet, 'v24') @@ -788,5 +1400,95 @@ def test_asset_locks_v2(self, node_wallet, node, pubkey): assert 'address' not in rpc_v1['assetLockTx']['creditOutputs'][0] + def test_non_standard(self, node_wallet, node, pubkey): + self.log.info("Testing that v2 and >100-input asset locks are non-standard...") + assert softfork_active(node_wallet, 'v24') + + coin = node_wallet.listunspent(query_options={'minimumAmount': 1}).pop() + lock_v2 = self.create_assetlock(coin, COIN, pubkey, version=2) + # reserve this coin so funding the split below can not spend it + node_wallet.lockunspent(False, [{'txid': coin['txid'], 'vout': coin['vout']}]) + + self.log.info("Split one coin into 101 outputs to build an asset lock with >100 inputs") + raw = node_wallet.createrawtransaction([], [{node_wallet.getnewaddress(): 1} for _ in range(101)]) + funded = node_wallet.fundrawtransaction(raw, {'change_position': 101})['hex'] + split_txid = node_wallet.sendrawtransaction(node_wallet.signrawtransactionwithwallet(funded)['hex']) + self.generate(node, 1) + many_coins = [{'txid': split_txid, 'vout': i, 'amount': 1} for i in range(101)] + tx_many_inputs = self.create_assetlock(many_coins, COIN, pubkey) + assert_equal(len(tx_many_inputs.vin), 101) + + self.log.info("A standard node (-acceptnonstdtxn=0) rejects them; the permissive node accepts them") + self.restart_node(1, self.extra_args[1] + ["-acceptnonstdtxn=0"]) + self.connect_nodes(1, 0) + + + for tx, reason in [(lock_v2, 'assetlocktx-version-2'), (tx_many_inputs, 'assetlocktx-too-many-inputs')]: + tx_hex = tx.serialize().hex() + assert_equal(node_wallet.testmempoolaccept([tx_hex])[0]['allowed'], True) + rejected = node.testmempoolaccept([tx_hex])[0] + assert_equal(rejected['allowed'], False) + assert_equal(rejected['reject-reason'], reason) + + self.log.info("They are still valid in a block: mine both and check the standard node accepts it") + txids = [node_wallet.sendrawtransaction(tx.serialize().hex()) for tx in [lock_v2, tx_many_inputs]] + block_hash = self.generate(node_wallet, 1)[0] + for checked_node in self.nodes: + for txid in txids: + assert txid in checked_node.getblock(block_hash)['tx'] + + self.log.info("The wallet refuses to build a v2 asset lock the local mempool would reject") + self.restart_node(0, self.extra_args[0] + ["-acceptnonstdtxn=0"]) + assert_raises_rpc_error(-6, "assetlocktx-version-2", node_wallet.sendtoaddress, + encode_platform_p2pkh('tdash', hash160(pubkey)), 1) + self.restart_node(0, self.extra_args[0]) + + self.restart_node(1, self.extra_args[1]) + self.connect_nodes(1, 0) + + def test_replay_after_crash(self, node_wallet, node, pubkey): + self.log.info("Testing recovery from a crash mid-flush with a quorum commitment and an asset unlock to replay...") + # Every flush now dies after its first partial write, so nothing mined from here on is flushed + self.restart_with_crashing_flush() + + self.mine_quorum_2_nodes() + quorum_hash = node_wallet.quorum("list", 1)["llmq_test_platform"][0] + commitment_block = node_wallet.quorum("info", llmq_type_test, quorum_hash)["minedBlock"] + txid = self.send_tx(self.create_assetunlock(900, COIN, pubkey)) + unlock_block = self.generate(node_wallet, 1)[0] + assert txid in node_wallet.getblock(unlock_block)["tx"] + + self.log.info("Restart without peers: the commitment block is replayed before the asset unlock block") + self.crash_and_replay(node_wallet, node, [commitment_block, unlock_block]) + assert quorum_hash in node_wallet.quorum("list")["llmq_test_platform"] + + self.log.info("Replay an asset unlock as the first block rolled forward, with the quorum already mature and flushed") + self.restart_node(0, self.extra_args[0]) + self.restart_with_crashing_flush() + txid = self.send_tx(self.create_assetunlock(901, COIN, pubkey)) + unlock_block = self.generate(node_wallet, 1)[0] + assert txid in node_wallet.getblock(unlock_block)["tx"] + self.crash_and_replay(node_wallet, node, [unlock_block]) + + self.restart_node(0, self.extra_args[0]) + for i in range(1, len(self.nodes)): + self.connect_nodes(0, i) + + def restart_with_crashing_flush(self): + self.restart_node(0, self.extra_args[0] + ["-dbcrashratio=1", "-dbbatchsize=1"]) + for i in range(1, len(self.nodes)): + self.connect_nodes(0, i) + + def crash_and_replay(self, node_wallet, node, replayed_blocks): + tip = node_wallet.getbestblockhash() + self.log.info("Force a flush, which crashes the node") + assert_raises((ConnectionError, http.client.CannotSendRequest, subprocess.CalledProcessError), node_wallet.gettxoutsetinfo) + self.wait_for_node_exit(0, timeout=10) + with node_wallet.assert_debug_log([f"Rolling forward {block}" for block in replayed_blocks]): + self.start_node(0, extra_args=self.extra_args[0] + ["-connect=0"]) + assert_equal(node_wallet.getbestblockhash(), tip) + assert_equal(node_wallet.gettxoutsetinfo()["hash_serialized_3"], node.gettxoutsetinfo()["hash_serialized_3"]) + + if __name__ == '__main__': AssetLocksTest().main() diff --git a/test/functional/feature_asset_locks_v24.py b/test/functional/feature_asset_locks_v24.py deleted file mode 100755 index b800b264f79d..000000000000 --- a/test/functional/feature_asset_locks_v24.py +++ /dev/null @@ -1,625 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright (c) 2026 The Dash Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. - -"""Test version 2 asset unlocks, non-standard asset locks and crash replay. - -Covers version 2 asset unlocks with stable txids, the non-standardness of -version 2 and >100-input asset locks, and recovery from a crash mid-flush that -leaves an asset unlock to replay. Everything else about asset locks, through -the v24 fork, is in feature_asset_locks.py. -""" - -import copy -import http.client -import subprocess -from decimal import Decimal -from io import BytesIO - -from test_framework.asset_locks import ( - AssetLocksMixin, - HEIGHT_DIFF_EXPIRING, - blocks_in_one_day, - llmq_type_test, - tiny_amount, -) -from test_framework.messages import ( - CAssetUnlockTx, - CCoinJoinBroadcastTx, - COIN, - MSG_ASSET_UNLOCK, - msg_dstx, - msg_tx, - tx_from_hex, -) -from test_framework.p2p import P2PInterface -from test_framework.script import hash160 -from test_framework.test_framework import DashTestFramework -from test_framework.util import ( - assert_equal, - assert_greater_than, - assert_greater_than_or_equal, - assert_raises, - assert_raises_rpc_error, - softfork_active, -) -from test_framework.segwit_addr import encode_platform_p2pkh -from test_framework.wallet_util import generate_keypair - -ASSET_UNLOCK_TX_TYPE = 9 # TRANSACTION_ASSET_UNLOCK -V24_ACTIVATION_HEIGHT = 250 -CREDIT_POOL_FUNDING = 5000 * COIN - - -class InvListener(P2PInterface): - def __init__(self): - super().__init__() - self.asset_unlock_invs = [] - - def on_inv(self, message): - for i in message.inv: - if i.type == MSG_ASSET_UNLOCK: - self.asset_unlock_invs.append(i.hash) - - -class AssetLocksV24Test(AssetLocksMixin, DashTestFramework): - def set_test_params(self): - # v24 is miner-activated here: the 250-block EHF window of the shipped deployment would - # cost minutes of mining, and the scenarios do not depend on how the fork was signalled - self.set_asset_locks_test_params([ - f"-vbparams=v24:0:999999999999:{V24_ACTIVATION_HEIGHT}:10:8:6:5:0", - ]) - - def run_test(self): - node_wallet = self.nodes[0] - node = self.nodes[1] - - self.set_sporks() - - assert_equal(self.nodes[0].getdeploymentinfo()['deployments']['v20']['active'], True) - - for _ in range(2): - self.dynamically_add_masternode(evo=True) - - privkey, pubkey = generate_keypair(wif=True) - node_wallet.importprivkey(privkey) - - self.fund_credit_pool(node_wallet, node, pubkey) - - self.log.info("Mine IS and platform quorums") - self.mine_quorum(llmq_type_name='llmq_test_instantsend', expected_members=2, expected_connections=1, expected_contributions=2, expected_commitments=2, llmq_type=104) - self.mine_quorum_2_nodes() - - self.activate_by_name('v24') - self.mine_quorum_2_nodes() - self.exhaust_unlock_window(node_wallet, node, pubkey) - - self.test_asset_unlock_v2(node_wallet, node, pubkey) - self.test_non_standard(node_wallet, node, pubkey) - self.test_replay_after_crash(node_wallet, node, pubkey) - - def fund_credit_pool(self, node_wallet, node, pubkey): - self.log.info("Fund the credit pool with a single asset lock, a whole withdrawal window before v24 is active") - coins = [] - total = 0 - for coin in node_wallet.listunspent(): - coins.append(coin) - total += int(coin['amount'] * COIN) - if total > CREDIT_POOL_FUNDING + COIN: - break - assert_greater_than(total, CREDIT_POOL_FUNDING + COIN) - self.send_tx(self.create_assetlock(coins, CREDIT_POOL_FUNDING, pubkey)) - self.generate(node, 1) - self.funding_height = node.getblockcount() - assert_greater_than_or_equal(int(node.getcreditpoolinfo()['balance'] * COIN), CREDIT_POOL_FUNDING) - - def current_limit(self, node): - return int(node.getcreditpoolinfo()['currentlimit'] * COIN) - - def exhaust_unlock_window(self, node_wallet, node, pubkey): - self.log.info("Exhaust the withdrawal limit and leave an over-limit unlock with a child in the mempool") - # A deposit inside the window would be withdrawable in full instead of the window's allowed drop - assert_greater_than(node.getblockcount() - blocks_in_one_day, self.funding_height) - # Far over the limit, so the rewards of the next blocks cannot make it minable - over_limit_tx = self.create_assetunlock(620, self.current_limit(node) + 100 * COIN, pubkey) - txid = self.send_tx(over_limit_tx) - tip_hash = self.generate(node, 1)[0] - assert txid not in node.getblock(tip_hash)['tx'] - - txid = self.send_tx(self.create_assetunlock(621, self.current_limit(node), pubkey)) - tip_hash = self.generate(node, 1)[0] - assert txid in node.getblock(tip_hash)['tx'] - assert_equal(self.current_limit(node), 0) - - over_limit_tx = self.create_assetunlock(622, 100 * COIN, pubkey) - txid = self.send_tx(over_limit_tx) - tip_hash = self.generate(node, 1)[0] - assert txid not in node.getblock(tip_hash)['tx'] - self.create_asset_unlock_child(node_wallet, over_limit_tx, txid) - - def test_asset_unlock_v2(self, node_wallet, node, pubkey): - self.log.info("Testing v2 asset unlocks with stable txids...") - assert softfork_active(node_wallet, 'v24') - self.log.info("Enable InstantSend: version 2 unlocks are locked once they are minable within the limit") - node_wallet.sporkupdate("SPORK_2_INSTANTSEND_ENABLED", 0) - self.wait_for_sporks_same() - - # The withdrawal window is exhausted by exhaust_unlock_window, so v2 instances created here stay - # unminable in the mempool until the window clears - index = 800 - listener = node_wallet.add_p2p_connection(InvListener()) - # A peer at the current protocol version supplies the first instance; refreshes of the - # withdrawal must still be announced to it later - sender = node_wallet.add_p2p_connection(InvListener()) - unlock_a = self.create_assetunlock(index, COIN, pubkey, version=2) - stable_txid = self.get_v2_txid(unlock_a) - instance_a = unlock_a.rehash() - assert stable_txid != instance_a - - sender.send_and_ping(msg_tx(unlock_a)) - self.wait_until(lambda: stable_txid in node_wallet.getrawmempool()) - self.sync_mempools() - rpc_tx = node_wallet.getrawtransaction(stable_txid, 1) - assert_equal(rpc_tx['txid'], stable_txid) - assert_equal(rpc_tx['instanceHash'], instance_a) - - self.log.info("The v2 unlock is announced by instance hash") - self.wait_until(lambda: int(instance_a, 16) in listener.asset_unlock_invs) - - self.log.info("Pending withdrawals exceed the limit, so the unlock is not locked while an ordinary tx is") - pending = node_wallet.getmempoolinfo()['pendingassetunlocks'] - # the over-limit unlocks left by exhaust_unlock_window exceed a whole window's allowed drop - info = node_wallet.getcreditpoolinfo() - allowed_drop = max(info['window']['balance'] * 20 / 100, 2000) - assert_greater_than(pending, allowed_drop) - assert_greater_than(pending, info['currentlimit']) - is_txid = node_wallet.sendtoaddress(node_wallet.getnewaddress(), 1) - self.wait_for_instantlock(is_txid) - assert_equal(node_wallet.getrawtransaction(stable_txid, 1)['instantlock'], False) - assert_equal(node_wallet.getassetunlockstatuses([str(index)])[0], {'index': index, 'status': 'mempooled', 'instantlock': False}) - - self.log.info("A second withdrawal refused on the limit is retried automatically once the window clears") - retry_index = 801 - unlock_retry = self.create_assetunlock(retry_index, COIN, pubkey, version=2) - retry_txid = self.get_v2_txid(unlock_retry) - assert_equal(self.send_tx_simple(unlock_retry), retry_txid) - self.sync_mempools() - assert_equal(node_wallet.getrawtransaction(retry_txid, 1)['instantlock'], False) - - self.log.info("Spend the unmined v2 unlock by its stable txid") - child_value = Decimal(unlock_a.vout[0].nValue - tiny_amount) / COIN - child_hex = node_wallet.createrawtransaction( - [{'txid': stable_txid, 'vout': 0}], - {node_wallet.getnewaddress(): child_value}) - signed_child = node_wallet.signrawtransactionwithwallet(child_hex) - assert signed_child['complete'] - child_txid = node_wallet.sendrawtransaction(signed_child['hex']) - self.sync_mempools() - assert child_txid in node_wallet.getrawmempool() - - def child_output(): - return next(u for u in node_wallet.listunspent(0) if u['txid'] == child_txid) - self.log.info("Without a lock on the withdrawal the wallet does not trust the child's output") - assert_equal(child_output()['safe'], False) - - self.log.info("A fresher re-signed instance refreshes the entry in place; same txid, child untouched") - self.generate(node, 1) - unlock_a2 = self.create_assetunlock(index, COIN, pubkey, version=2) - assert_equal(self.get_v2_txid(unlock_a2), stable_txid) - instance_a2 = unlock_a2.rehash() - assert instance_a2 != instance_a - assert_equal(self.send_tx_simple(unlock_a2), stable_txid) - self.sync_unlock_instance(stable_txid, instance_a2) - mempool = node_wallet.getrawmempool() - assert stable_txid in mempool - assert child_txid in mempool - self.log.info("The refresh is announced under its own instance hash, including to the peer that sent the first instance") - self.wait_until(lambda: int(instance_a2, 16) in listener.asset_unlock_invs) - self.wait_until(lambda: int(instance_a2, 16) in sender.asset_unlock_invs) - assert int(instance_a, 16) not in sender.asset_unlock_invs - - self.log.info("A stale instance does not refresh a fresher one") - assert_raises_rpc_error(-26, 'assetunlock-stale-instance', self.send_tx_simple, unlock_a) - - self.log.info("A stale instance in a package is rejected by the refresh path; the fresher held instance stays") - stale_package_child_hex = node_wallet.createrawtransaction( - [{'txid': stable_txid, 'vout': 0}], - {node_wallet.getnewaddress(): child_value}) - signed_stale_package_child = node_wallet.signrawtransactionwithwallet(stale_package_child_hex) - assert signed_stale_package_child['complete'] - assert_raises_rpc_error(-26, f'{stable_txid} failed: assetunlock-stale-instance', node_wallet.submitpackage, - [unlock_a.serialize().hex(), signed_stale_package_child['hex']]) - assert_equal(node_wallet.getrawtransaction(stable_txid, 1)['instanceHash'], instance_a2) - assert child_txid in node_wallet.getrawmempool() - - self.log.info("Package test acceptance treats the held withdrawal as already in the mempool") - # A multi-transaction testmempoolaccept must not route the mempooled unlock through the - # in-place refresh path: that used to leave the package feerate accounting unfilled and - # abort the node. Refreshes are only admitted through single-transaction submission. - funded = node_wallet.fundrawtransaction(node_wallet.createrawtransaction([], {node_wallet.getnewaddress(): 1})) - signed_sibling = node_wallet.signrawtransactionwithwallet(funded['hex']) - assert signed_sibling['complete'] - package_result = node_wallet.testmempoolaccept([unlock_a2.serialize().hex(), signed_sibling['hex']]) - assert_equal(package_result[0]['txid'], stable_txid) - assert_equal(package_result[0]['allowed'], False) - assert_equal(package_result[0]['reject-reason'], 'txn-already-in-mempool') - - self.log.info("Expire the v2 instance; it and its child must survive in the mempool") - self.generate_batch(HEIGHT_DIFF_EXPIRING + 1) - mempool = node_wallet.getrawmempool() - assert stable_txid in mempool - assert child_txid in mempool - assert retry_txid in mempool - - self.log.info("A node without the expired instances admits them and the child from a peer") - expired_hexes = [node_wallet.getrawtransaction(txid) for txid in (stable_txid, retry_txid, child_txid)] - # Stopping dumps node's mempool, which the -persistmempool=0 run neither loads nor overwrites - self.restart_node(1, self.extra_args[1] + ["-persistmempool=0"]) - assert stable_txid not in node.getrawmempool() - expired_peer = node.add_p2p_connection(P2PInterface()) - with node.assert_debug_log(expected_msgs=[], unexpected_msgs=["Misbehaving"]): - for tx_hex in expired_hexes: - expired_peer.send_and_ping(msg_tx(tx_from_hex(tx_hex))) - mempool = node.getrawmempool() - assert stable_txid in mempool - assert retry_txid in mempool - assert child_txid in mempool - - self.log.info("An expired instance must still carry a signature valid at its requestedHeight") - forged = tx_from_hex(expired_hexes[0]) - forged_payload = CAssetUnlockTx() - forged_payload.deserialize(BytesIO(forged.vExtraPayload)) - forged_payload.index = 810 - forged.vExtraPayload = forged_payload.serialize() - forged_peer = node.add_p2p_connection(P2PInterface()) - with node.assert_debug_log(expected_msgs=["bad-assetunlock-not-verified", "Misbehaving: peer=", "(0 -> 100)"]): - forged_peer.send_and_ping(msg_tx(forged)) - node.disconnect_p2ps() - - self.log.info("A requestedHeight overflowing the height window is rejected as too late") - overflow_unlock = self.create_assetunlock(812, COIN, pubkey, version=2, requested_height=2**32 - HEIGHT_DIFF_EXPIRING) - assert_equal(node.testmempoolaccept([overflow_unlock.serialize().hex()])[0]['reject-reason'], 'bad-assetunlock-too-late') - - self.log.info("An expired instance signed by a quorum mined after its requestedHeight is admitted") - late_index = 811 - late_quorum = self.mninfo[0].get_node(self).quorum("selectquorum", llmq_type_test, self.create_assetunlock_request_id(late_index))["quorumHash"] - late_quorum_mined_height = node.getblock(node.quorum("info", llmq_type_test, late_quorum)["minedBlock"])["height"] - late_quorum_unlock = self.create_assetunlock(late_index, COIN, pubkey, version=2, requested_height=late_quorum_mined_height - 1) - blocks_to_expiry = late_quorum_mined_height - 1 + HEIGHT_DIFF_EXPIRING - node.getblockcount() - if blocks_to_expiry > 0: - # node is still disconnected from node_wallet after its restart above - self.generate(node, blocks_to_expiry, sync_fun=self.no_op) - assert_equal(node.testmempoolaccept([late_quorum_unlock.serialize().hex()])[0]['allowed'], True) - - self.log.info("The expired instances and the child survive a restart") - self.restart_node(1, self.extra_args[1]) - mempool = node.getrawmempool() - assert stable_txid in mempool - assert retry_txid in mempool - assert child_txid in mempool - self.connect_nodes(1, 0) - self.sync_all() - - self.log.info("Flush the leftover withdrawals and clear the window; the expired instance keeps waiting for a re-sign") - # The pending unlocks of exhaust_unlock_window would otherwise consume the cleared window and - # crowd this test's withdrawal out of the block. Mine until each of them is either mined - # or expired and evicted; the expired instance under test cannot be mined and stays. - - def other_unlocks_pending(): - self.sync_mempools() - return any(txid not in (stable_txid, retry_txid) and node_wallet.getrawtransaction(txid, 1)['type'] == ASSET_UNLOCK_TX_TYPE - for txid in node_wallet.getrawmempool()) - flushed = 0 - while other_unlocks_pending(): - self.generate(node, 1) - flushed += 1 - assert flushed <= 2 * blocks_in_one_day, "leftover withdrawals never left the mempool" - self.generate_batch(101) - mempool = node_wallet.getrawmempool() - assert stable_txid in mempool - assert child_txid in mempool - self.log.info("A whole window later the allowance has regenerated to at least the 2000 DASH floor") - assert_greater_than_or_equal(node_wallet.getcreditpoolinfo()['currentlimit'], 2000) - - self.log.info("Both expired instances fit the cleared limit but are not minable, so neither is locked") - assert_equal(node_wallet.getmempoolinfo()['pendingassetunlocks'], 2 * Decimal(unlock_a.vout[0].nValue + tiny_amount) / COIN) - assert_equal(node_wallet.getrawtransaction(stable_txid, 1)['instantlock'], False) - assert_equal(node_wallet.getrawtransaction(retry_txid, 1)['instantlock'], False) - - self.log.info("Refreshing the second withdrawal gets it locked: the per-block retry re-evaluates it against the cleared limit") - unlock_retry_b = self.create_assetunlock(retry_index, COIN, pubkey, version=2) - assert_equal(self.send_tx_simple(unlock_retry_b), retry_txid) - self.sync_unlock_instance(retry_txid, unlock_retry_b.rehash()) - self.wait_for_instantlock(retry_txid) - self.generate(node, 1) - assert retry_txid not in node_wallet.getrawmempool() - - self.log.info("Refresh the expired instance with a fresh re-sign: minable and within the limit, it gets locked") - unlock_b = self.create_assetunlock(index, COIN, pubkey, version=2) - assert_equal(self.get_v2_txid(unlock_b), stable_txid) - assert_equal(self.send_tx_simple(unlock_b), stable_txid) - self.sync_unlock_instance(stable_txid, unlock_b.rehash()) - self.wait_for_instantlock(stable_txid) - assert_equal(node_wallet.getassetunlockstatuses([str(index)])[0], {'index': index, 'status': 'mempooled', 'instantlock': True}) - self.log.info("The lock pins the withdrawal index as the unlock's single input") - islock = node_wallet.getislocks([stable_txid])[0] - assert_equal(islock['inputs'], [{'txid': self.create_assetunlock_request_id(index), 'vout': 0}]) - self.log.info("The child is an ordinary spend of a locked parent: it gets locked and the wallet trusts it") - self.wait_for_instantlock(child_txid) - assert_equal(child_output()['safe'], True) - - self.log.info("A peer relaying an older instance of the locked withdrawal does not strip the locks") - # The rejected instance shares the txid of the locked one still held in the mempool - stale_peer = node_wallet.add_p2p_connection(P2PInterface()) - with node_wallet.assert_debug_log([f"{stable_txid} from peer=", "was not accepted"]): - stale_peer.send_and_ping(msg_tx(unlock_a2)) - assert_equal(node_wallet.getrawtransaction(stable_txid, 1)['instanceHash'], unlock_b.rehash()) - assert_equal(node_wallet.getrawtransaction(stable_txid, 1)['instantlock'], True) - assert_equal(node_wallet.getrawtransaction(child_txid, 1)['instantlock'], True) - - self.log.info("Mine the withdrawal with its child") - tip_hash = self.generate(node, 1)[0] - block = node_wallet.getblock(tip_hash, 2) - mined_txids = [t['txid'] for t in block['tx']] - assert stable_txid in mined_txids - assert child_txid in mined_txids - # The coinbase commits to the mined instance's hash; a single leaf is its own merkle root - assert_equal(block['cbTx']['merkleRootAssetUnlocks'], unlock_b.rehash()) - assert_equal(node_wallet.getassetunlockstatuses([str(index)])[0], {'index': index, 'status': 'mined'}) - child_rpc = node_wallet.getrawtransaction(child_txid, 1) - assert_equal(child_rpc['vin'][0]['txid'], stable_txid) - assert_equal(node_wallet.getrawtransaction(stable_txid, 1)['instantlock'], True) - - self.log.info("At most one instance of a withdrawal index is held: a version 1 instance signed one block earlier is the claimant") - cross_index = 803 - tip_height = node_wallet.getblockcount() - unlock_v1 = self.create_assetunlock(cross_index, COIN, pubkey, version=1, requested_height=tip_height - 1) - v1_txid = self.send_tx_simple(unlock_v1) - self.sync_mempools() - - self.log.info("A version 2 instance signed at the same height is stale: rejected before its signature is verified") - unlock_v2_stale = self.create_assetunlock(cross_index, COIN, pubkey, version=2, requested_height=tip_height - 1) - stale_result = node_wallet.testmempoolaccept([unlock_v2_stale.serialize().hex()])[0] - assert_equal(stale_result['txid'], self.get_v2_txid(unlock_v2_stale)) - assert_equal(stale_result['allowed'], False) - assert_equal(stale_result['reject-reason'], 'assetunlock-stale-instance') - assert v1_txid in node_wallet.getrawmempool() - - unlock_v2_fresh = self.create_assetunlock(cross_index, COIN, pubkey, version=2, requested_height=tip_height) - cross_txid = self.get_v2_txid(unlock_v2_fresh) - self.log.info("A package cannot replace an unlock while spending the evicted claimant") - package_child_hex = node_wallet.createrawtransaction( - [{'txid': v1_txid, 'vout': 0}, {'txid': cross_txid, 'vout': 0}], - {node_wallet.getnewaddress(): Decimal(unlock_v1.vout[0].nValue + unlock_v2_fresh.vout[0].nValue - tiny_amount) / COIN}) - fresh_prevout = {'txid': cross_txid, 'vout': 0, 'scriptPubKey': unlock_v2_fresh.vout[0].scriptPubKey.hex(), - 'amount': Decimal(unlock_v2_fresh.vout[0].nValue) / COIN} - signed_package_child = node_wallet.signrawtransactionwithwallet(package_child_hex, [fresh_prevout]) - assert signed_package_child['complete'] - assert_raises_rpc_error(-25, 'assetunlock-conflicting-package', node_wallet.submitpackage, - [unlock_v1.serialize().hex(), unlock_v2_fresh.serialize().hex(), signed_package_child['hex']]) - assert v1_txid in node_wallet.getrawmempool() - assert cross_txid not in node_wallet.getrawmempool() - - self.log.info("Package test acceptance predicts that rejection rather than validating the child against the evicted claimant") - evicted_child_hex = node_wallet.createrawtransaction( - [{'txid': v1_txid, 'vout': 0}], - {node_wallet.getnewaddress(): Decimal(unlock_v1.vout[0].nValue - tiny_amount) / COIN}) - signed_evicted_child = node_wallet.signrawtransactionwithwallet(evicted_child_hex) - assert signed_evicted_child['complete'] - test_result = node_wallet.testmempoolaccept([unlock_v2_fresh.serialize().hex(), signed_evicted_child['hex']]) - assert_equal([r['txid'] for r in test_result], [cross_txid, node_wallet.decoderawtransaction(signed_evicted_child['hex'])['txid']]) - for r in test_result: - assert_equal(r['package-error'], 'assetunlock-conflicting-package') - assert 'allowed' not in r - assert v1_txid in node_wallet.getrawmempool() - assert cross_txid not in node_wallet.getrawmempool() - - self.log.info("A version 2 unlock wrapped in a dstx message goes through DSTX validation and is dropped") - dstx_peer = node_wallet.add_p2p_connection(P2PInterface()) - wrapped = CCoinJoinBroadcastTx(tx=unlock_v2_fresh, m_protxHash=1, vchSig=b"\x01" * 96, sigTime=self.mocktime) - with node_wallet.assert_debug_log(["Invalid DSTX structure", "invalid dstx"]): - dstx_peer.send_and_ping(msg_dstx(wrapped)) - assert cross_txid not in node_wallet.getrawmempool() - assert v1_txid in node_wallet.getrawmempool() - - self.log.info("Signed one block later, the version 2 instance is fresher: it replaces the version 1 claimant and gets locked") - assert_equal(self.send_tx_simple(unlock_v2_fresh), cross_txid) - self.sync_mempools() - mempool = node_wallet.getrawmempool() - assert cross_txid in mempool - assert v1_txid not in mempool - assert_equal(node_wallet.getmempoolinfo()['pendingassetunlocks'], Decimal(unlock_v2_fresh.vout[0].nValue + tiny_amount) / COIN) - self.wait_for_instantlock(cross_txid) - assert_equal(node_wallet.getassetunlockstatuses([str(cross_index)])[0], {'index': cross_index, 'status': 'mempooled', 'instantlock': True}) - tip_hash = self.generate(node, 1)[0] - assert cross_txid in node_wallet.getblock(tip_hash)['tx'] - - self.log.info("A rejected instance does not blacklist the txid shared by every instance of its withdrawal") - # The node does not hold this withdrawal yet. An instance with a tampered requestedHeight - # fails validation but carries the txid of the valid one, which a child already spends. - orphan_index = 804 - unlock_valid = self.create_assetunlock(orphan_index, COIN, pubkey, version=2) - parent_txid = self.get_v2_txid(unlock_valid) - tampered_payload = CAssetUnlockTx() - tampered_payload.deserialize(BytesIO(unlock_valid.vExtraPayload)) - tampered_payload.requestedHeight -= 1 - unlock_tampered = copy.deepcopy(unlock_valid) - unlock_tampered.vExtraPayload = tampered_payload.serialize() - assert_equal(self.get_v2_txid(unlock_tampered), parent_txid) - assert unlock_tampered.rehash() != unlock_valid.rehash() - - parent_value = unlock_valid.vout[0].nValue - orphan_child_hex = node_wallet.createrawtransaction( - [{'txid': parent_txid, 'vout': 0}], - {node_wallet.getnewaddress(): Decimal(parent_value - tiny_amount) / COIN}) - parent_prevout = {'txid': parent_txid, 'vout': 0, 'scriptPubKey': unlock_valid.vout[0].scriptPubKey.hex(), - 'amount': Decimal(parent_value) / COIN} - signed_orphan_child = node_wallet.signrawtransactionwithwallet(orphan_child_hex, [parent_prevout]) - assert signed_orphan_child['complete'] - orphan_child = tx_from_hex(signed_orphan_child['hex']) - orphan_child_txid = orphan_child.rehash() - - relay_peer = node_wallet.add_p2p_connection(P2PInterface()) - with node_wallet.assert_debug_log([f"{parent_txid} from peer=", "was not accepted"]): - relay_peer.send_and_ping(msg_tx(unlock_tampered)) - assert parent_txid not in node_wallet.getrawmempool() - - self.log.info("A child spending the withdrawal is kept as an orphan and accepted with its valid parent") - with node_wallet.assert_debug_log(expected_msgs=[], unexpected_msgs=["not keeping orphan with rejected parents"]): - relay_peer.send_and_ping(msg_tx(orphan_child)) - assert orphan_child_txid not in node_wallet.getrawmempool() - relay_peer.send_and_ping(msg_tx(unlock_valid)) - mempool = node_wallet.getrawmempool() - assert parent_txid in mempool - assert orphan_child_txid in mempool - self.wait_for_instantlock(parent_txid, orphan_child_txid) - tip_hash = self.generate(node, 1)[0] - mined_txids = node_wallet.getblock(tip_hash)['tx'] - assert parent_txid in mined_txids - assert orphan_child_txid in mined_txids - - self.log.info("A peer relaying an older instance of an unlocked withdrawal does not keep it from being locked later") - # A pending withdrawal over the credit pool limit keeps this one from being locked until it - # expires; the per-block retry must then lock it without another re-sign - tip_height = node_wallet.getblockcount() - blocker = self.create_assetunlock(805, 4001 * COIN, pubkey, version=1, - requested_height=tip_height - HEIGHT_DIFF_EXPIRING + 2) - blocker_txid = self.send_tx_simple(blocker) - unlock_old = self.create_assetunlock(806, COIN, pubkey, version=2) - retry_lock_txid = self.get_v2_txid(unlock_old) - assert_equal(self.send_tx_simple(unlock_old), retry_lock_txid) - self.sync_mempools() - # Empty blocks keep the withdrawal unmined while the blocker is pending - self.generateblock(node, node_wallet.getnewaddress(), []) - unlock_new = self.create_assetunlock(806, COIN, pubkey, version=2) - assert_equal(self.send_tx_simple(unlock_new), retry_lock_txid) - self.sync_unlock_instance(retry_lock_txid, unlock_new.rehash()) - assert blocker_txid in node_wallet.getrawmempool() - assert_equal(node_wallet.getrawtransaction(retry_lock_txid, 1)['instantlock'], False) - - for mn in self.mninfo: - mn_node = mn.get_node(self) - with mn_node.assert_debug_log([f"{retry_lock_txid} from peer=", "assetunlock-stale-instance"]): - mn_node.add_p2p_connection(P2PInterface()).send_and_ping(msg_tx(unlock_old)) - mn_node.disconnect_p2ps() - - self.log.info("Once the blocking withdrawal expires, the per-block retry locks the unlock") - for _ in range(3): - if blocker_txid not in node_wallet.getrawmempool(): - break - self.generateblock(node, node_wallet.getnewaddress(), []) - assert blocker_txid not in node_wallet.getrawmempool() - assert retry_lock_txid in node_wallet.getrawmempool() - self.wait_for_instantlock(retry_lock_txid) - tip_hash = self.generate(node, 1)[0] - assert retry_lock_txid in node_wallet.getblock(tip_hash)['tx'] - - node_wallet.disconnect_p2ps() - self.set_sporks() - self.mempool_size = node_wallet.getmempoolinfo()['size'] - self.check_mempool_size() - - def test_non_standard(self, node_wallet, node, pubkey): - self.log.info("Testing that v2 and >100-input asset locks are non-standard...") - assert softfork_active(node_wallet, 'v24') - - coin = node_wallet.listunspent(query_options={'minimumAmount': 1}).pop() - lock_v2 = self.create_assetlock(coin, COIN, pubkey, version=2) - # reserve this coin so funding the split below can not spend it - node_wallet.lockunspent(False, [{'txid': coin['txid'], 'vout': coin['vout']}]) - - self.log.info("Split one coin into 101 outputs to build an asset lock with >100 inputs") - raw = node_wallet.createrawtransaction([], [{node_wallet.getnewaddress(): 1} for _ in range(101)]) - funded = node_wallet.fundrawtransaction(raw, {'change_position': 101})['hex'] - split_txid = node_wallet.sendrawtransaction(node_wallet.signrawtransactionwithwallet(funded)['hex']) - self.generate(node, 1) - many_coins = [{'txid': split_txid, 'vout': i, 'amount': 1} for i in range(101)] - tx_many_inputs = self.create_assetlock(many_coins, COIN, pubkey) - assert_equal(len(tx_many_inputs.vin), 101) - - self.log.info("A standard node (-acceptnonstdtxn=0) rejects them; the permissive node accepts them") - self.restart_node(1, self.extra_args[1] + ["-acceptnonstdtxn=0"]) - self.connect_nodes(1, 0) - - - for tx, reason in [(lock_v2, 'assetlocktx-version-2'), (tx_many_inputs, 'assetlocktx-too-many-inputs')]: - tx_hex = tx.serialize().hex() - assert_equal(node_wallet.testmempoolaccept([tx_hex])[0]['allowed'], True) - rejected = node.testmempoolaccept([tx_hex])[0] - assert_equal(rejected['allowed'], False) - assert_equal(rejected['reject-reason'], reason) - - self.log.info("They are still valid in a block: mine both and check the standard node accepts it") - txids = [node_wallet.sendrawtransaction(tx.serialize().hex()) for tx in [lock_v2, tx_many_inputs]] - block_hash = self.generate(node_wallet, 1)[0] - for checked_node in self.nodes: - for txid in txids: - assert txid in checked_node.getblock(block_hash)['tx'] - - self.log.info("The wallet refuses to build a v2 asset lock the local mempool would reject") - self.restart_node(0, self.extra_args[0] + ["-acceptnonstdtxn=0"]) - assert_raises_rpc_error(-6, "assetlocktx-version-2", node_wallet.sendtoaddress, - encode_platform_p2pkh('tdash', hash160(pubkey)), 1) - self.restart_node(0, self.extra_args[0]) - - self.restart_node(1, self.extra_args[1]) - self.connect_nodes(1, 0) - - def test_replay_after_crash(self, node_wallet, node, pubkey): - self.log.info("Testing recovery from a crash mid-flush with a quorum commitment and an asset unlock to replay...") - # Every flush now dies after its first partial write, so nothing mined from here on is flushed - self.restart_with_crashing_flush() - - self.mine_quorum_2_nodes() - quorum_hash = node_wallet.quorum("list", 1)["llmq_test_platform"][0] - commitment_block = node_wallet.quorum("info", llmq_type_test, quorum_hash)["minedBlock"] - txid = self.send_tx(self.create_assetunlock(900, COIN, pubkey)) - unlock_block = self.generate(node_wallet, 1)[0] - assert txid in node_wallet.getblock(unlock_block)["tx"] - - self.log.info("Restart without peers: the commitment block is replayed before the asset unlock block") - self.crash_and_replay(node_wallet, node, [commitment_block, unlock_block]) - assert quorum_hash in node_wallet.quorum("list")["llmq_test_platform"] - - self.log.info("Replay an asset unlock as the first block rolled forward, with the quorum already mature and flushed") - self.restart_with_crashing_flush() - txid = self.send_tx(self.create_assetunlock(901, COIN, pubkey)) - unlock_block = self.generate(node_wallet, 1)[0] - assert txid in node_wallet.getblock(unlock_block)["tx"] - self.crash_and_replay(node_wallet, node, [unlock_block]) - - self.restart_node(0, self.extra_args[0]) - for i in range(1, len(self.nodes)): - self.connect_nodes(0, i) - - def restart_with_crashing_flush(self): - self.restart_node(0, self.extra_args[0] + ["-dbcrashratio=1", "-dbbatchsize=1"]) - for i in range(1, len(self.nodes)): - self.connect_nodes(0, i) - - def crash_and_replay(self, node_wallet, node, replayed_blocks): - tip = node_wallet.getbestblockhash() - self.log.info("Force a flush, which crashes the node") - assert_raises((ConnectionError, http.client.CannotSendRequest, subprocess.CalledProcessError), node_wallet.gettxoutsetinfo) - self.wait_for_node_exit(0, timeout=10) - with node_wallet.assert_debug_log([f"Rolling forward {block}" for block in replayed_blocks]): - self.start_node(0, extra_args=self.extra_args[0] + ["-connect=0"]) - assert_equal(node_wallet.getbestblockhash(), tip) - assert_equal(node_wallet.gettxoutsetinfo()["hash_serialized_3"], node.gettxoutsetinfo()["hash_serialized_3"]) - - def sync_unlock_instance(self, txid, instance_hash): - # A re-signed instance shares the held entry's txid, so sync_mempools() is satisfied - # before the refresh has propagated; wait for every node to hold this exact instance. - # Refreshes travel as MSG_ASSET_UNLOCK invs on the trickle schedule, which needs time - # to advance. - def synced(): - self.bump_mocktime(1) - return all(node.getrawtransaction(txid, 1).get('instanceHash') == instance_hash - for node in self.nodes) - self.wait_until(synced, timeout=60) - - -if __name__ == '__main__': - AssetLocksV24Test().main() diff --git a/test/functional/feature_dip3_deterministicmns.py b/test/functional/feature_dip3_deterministicmns.py index 06a5422eea6b..602a9db6301a 100755 --- a/test/functional/feature_dip3_deterministicmns.py +++ b/test/functional/feature_dip3_deterministicmns.py @@ -24,7 +24,7 @@ def add_options(self, parser): self.add_wallet_options(parser) def set_test_params(self): - self.num_initial_mn = 5 + self.num_initial_mn = 11 # Should be >= 11 to make sure quorums are not always the same MNs self.num_nodes = 1 + self.num_initial_mn + 2 # +1 for controller, +1 for mn-qt, +1 for mn created after dip3 activation self.setup_clean_chain = True self.disable_mocktime = True @@ -184,13 +184,13 @@ def dip3_inactive_error(): self.assert_mnlists(mns_tmp) self.log.info("test mn payment enforcement with deterministic MNs") - for i in range(3): + for i in range(20): node = self.nodes[i % len(self.nodes)] self.test_invalid_mn_payment(mns, node) self.generate(self.nodes[0], 1) self.log.info("testing ProUpServTx") - for mn in mns[:2]: + for mn in mns: self.test_protx_update_service(mn) self.log.info("testing P2SH/multisig for payee addresses") @@ -221,7 +221,7 @@ def dip3_inactive_error(): assert found_multisig_payee self.log.info("testing reusing of collaterals for replaced MNs") - for i in range(2): + for i in range(5): mn = mns[i] # a few of these will actually refer to old ProRegTx internal collaterals, # which should work the same as external collaterals diff --git a/test/functional/feature_dip4_coinbasemerkleroots.py b/test/functional/feature_dip4_coinbasemerkleroots.py index 2f7150b3d7af..56d14497c139 100755 --- a/test/functional/feature_dip4_coinbasemerkleroots.py +++ b/test/functional/feature_dip4_coinbasemerkleroots.py @@ -32,7 +32,6 @@ def add_options(self, parser): self.add_wallet_options(parser) def set_test_params(self): - self.noban_tx_relay = True self.extra_args = [[ f'-testactivationheight=dip0008@{DIP0008_HEIGHT}', f'-testactivationheight=dip0024@{DIP0024_HEIGHT}', "-vbparams=testdummy:999999999999:999999999999" ]] * 4 self.set_dash_test_params(4, 3, extra_args = self.extra_args) self.delay_v20_and_mn_rr(height=V20_HEIGHT) @@ -284,9 +283,6 @@ def test_dip8_quorum_merkle_root_activation(self, with_initial_quorum, slow_mode else: assert_equal(merkleRootQuorums, 0) - if with_initial_quorum: - return - self.bump_mocktime(1) self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0) self.wait_for_sporks_same() diff --git a/test/functional/feature_governance.py b/test/functional/feature_governance.py index cfcbfc843807..000370780d25 100755 --- a/test/functional/feature_governance.py +++ b/test/functional/feature_governance.py @@ -8,6 +8,8 @@ """ import json +import os +import shutil import struct from test_framework.messages import ( @@ -24,10 +26,11 @@ from test_framework.test_framework import ( DashTestFramework, ) -from test_framework.governance import have_trigger_for_height, prepare_object +from test_framework.governance import EXPECTED_STDERR_GOV_PRUNED_TOO_FAR, have_trigger_for_height, prepare_object from test_framework.util import assert_equal, assert_raises_rpc_error, force_finish_mnsync, satoshi_round GOVERNANCE_UPDATE_MIN = 60 * 60 # src/governance/object.h +MIN_BLOCKS_TO_KEEP = 288 # src/validation.h BUDGET_ARGS = ["-budgetparams=10:10:10"] @@ -180,6 +183,8 @@ def run_test(self): pruned_node = self.nodes[1] assert pruned_node.getblockchaininfo()["pruned"] assert "txindex" not in pruned_node.getindexinfo() + # Funds a proposal on the pruned node + self.nodes[0].sendtoaddress(pruned_node.getnewaddress(), 10) self.log.info("Check 1st superblock before v20") self.bump_mocktime(3) @@ -207,6 +212,10 @@ def run_test(self): p0_collateral_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_0", self.p0_amount, self.p0_payout_address) p1_collateral_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_1", self.p1_amount, self.p1_payout_address) p2_collateral_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_2", self.p2_amount, self.p2_payout_address) + # The pruned node prepares a proposal too, but only submits it once the block with its collateral is pruned + assert_equal(pruned_node.getbalance(), 10) + p3_collateral_prepare = prepare_object(pruned_node, 1, uint256_to_string(0), proposal_time, 1, "Proposal_3", 1, pruned_node.getnewaddress()) + self.sync_mempools([self.nodes[0], pruned_node]) self.bump_mocktime(6) self.generate(self.nodes[0], 6, sync_fun=self.sync_blocks) @@ -388,23 +397,12 @@ def sync_gov(node): self.log.info("let all fulfilled requests expire for re-sync to work correctly") self.bump_mocktime(5 * 60) - both_triggers = {winning_trigger_hash, isolated_trigger_hash} - # 15 votes on the proposals, the 4 YES votes on the winning trigger and the 1 YES vote on the isolated one - total_votes = 20 - def resync_gov(node): # Force sync node.mnsync("reset") # fast-forward to governance sync node.mnsync("next") - - def has_everything(): - # The sync tick asks one peer per MASTERNODE_SYNC_TICK_SECONDS of mocktime - self.bump_mocktime(1) - return both_triggers <= self.valid_triggers(node) and node.gobject("count")["votes"] == total_votes - self.wait_until(has_everything) - # Peers ignore governance sync requests until they are synced themselves - force_finish_mnsync(node) + self.wait_until(lambda: sync_gov(node)) # Node 0 asks one peer every few seconds, so with the pruned node as an extra peer its governance sync would # time out before it asks the reconnected payee. The pruned node syncs from node 0 afterwards instead. @@ -419,6 +417,7 @@ def has_everything(): self.wait_until(lambda: len(isolated.gobject("list", "valid", "triggers")) == 2, timeout=5) self.wait_until(lambda: len(self.nodes[0].gobject("list", "valid", "triggers")) == 2, timeout=5) # Every masternode must know both triggers before the next block so that it votes on them there + both_triggers = {winning_trigger_hash, isolated_trigger_hash} self.wait_until(lambda: all(both_triggers <= self.valid_triggers(node) for node in self.nodes), timeout=5) def yes_votes_known(node, trigger_hash, yes_count): @@ -527,8 +526,27 @@ def yes_votes_known(node, trigger_hash, yes_count): assert_equal(self.nodes[0].getblockcount(), 180) assert_equal(self.nodes[0].getdeploymentinfo()["deployments"]["v20"]["active"], True) + self.log.info("Mine and check a couple more superblocks") + for i in range(2): + sb_block_height = 180 + (i + 1) * sb_cycle + self.bump_mocktime(sb_immaturity_window) + self.generate(self.nodes[0], sb_immaturity_window, sync_fun=self.sync_blocks) + for _ in range(sb_maturity_window - 1): + self.bump_mocktime(1) + self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks) + self.wait_until(lambda: have_trigger_for_height(self.nodes, sb_block_height), timeout=1, do_assert=False) + # Wait for new trigger and votes + self.wait_until(lambda: have_trigger_for_height(self.nodes, sb_block_height)) + # Mine superblock + self.bump_mocktime(1) + self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks) + assert_equal(self.nodes[0].getblockcount(), sb_block_height) + assert_equal(self.nodes[0].getdeploymentinfo()["deployments"]["v20"]["active"], True) + self.check_superblockbudget(True) + self.check_superblock() + self.log.info("A matching trigger relayed before the maturity window must still be funded") - sb_block_height = 200 + sb_block_height = 240 window_start = sb_block_height - sb_maturity_window # Blocks above came faster than 2.5 minutes apart, so get clear of the per-masternode trigger rate limit self.bump_mocktime(3 * sb_cycle * 150, update_schedulers=False) @@ -577,6 +595,73 @@ def early_trigger_relayed(): assert_equal(self.nodes[0].getblockcount(), sb_block_height) self.check_superblock() + self.test_pruned_node(p3_collateral_prepare) + + def test_pruned_node(self, proposal): + pruned_node = self.nodes[1] + + def submit(): + return pruned_node.gobject("submit", "0", 1, proposal["createdAt"], proposal["hex"], proposal["collateralHash"]) + + self.log.info("The pruned node finds collateral whose block it has pruned") + collateral_height = self.nodes[0].getrawtransaction(proposal["collateralHash"], True)["height"] + # Otherwise the masternodes keep creating triggers, and the burst of blocks below may leave out a superblock + # that one node already knows the trigger for but the other doesn't + for mn in self.mninfo: + self.isolate_node(mn.nodeIdx) + # Each -fastprune block file holds dozens of blocks, so mine enough to prune the collateral's whole file + self.bump_mocktime(MIN_BLOCKS_TO_KEEP + 150) + self.generate(self.nodes[0], MIN_BLOCKS_TO_KEEP + 150, sync_fun=lambda: self.sync_blocks(self.nodes[0:2])) + pruned_node.pruneblockchain(pruned_node.getblockcount() - MIN_BLOCKS_TO_KEEP) + assert pruned_node.getblockchaininfo()["pruneheight"] > collateral_height + assert_raises_rpc_error(-1, "Block not available (pruned data)", pruned_node.getblock, + pruned_node.getblockhash(collateral_height)) + proposal_hash = submit() + self.wait_until(lambda: proposal_hash in self.nodes[0].gobject("list", "valid", "proposals")) + + self.log.info("Governance objects survive a restart of the pruned node") + self.restart_node(1) + force_finish_mnsync(pruned_node) + self.connect_nodes(0, 1) + assert proposal_hash in pruned_node.gobject("list", "valid", "proposals") + self.log.info("The reopened index still finds the pruned collateral") + self.wait_until(lambda: pruned_node.getindexinfo()["govcollateralindex"]["synced"]) + assert_equal(submit(), proposal_hash) + + self.log.info("A node that pruned before it had the index starts with governance off instead of failing") + self.stop_node(1) + shutil.rmtree(os.path.join(pruned_node.chain_path, "indexes", "govcollateralindex")) + self.start_node(1) + assert "govcollateralindex" not in pruned_node.getindexinfo() + assert_raises_rpc_error(-1, "Preparing a proposal now would burn its fee", pruned_node.gobject, "prepare", + "0", 1, proposal["createdAt"], proposal["hex"]) + assert_raises_rpc_error(-1, "Governance is disabled on this node", submit) + self.stop_node(1, expected_stderr=EXPECTED_STDERR_GOV_PRUNED_TOO_FAR) + + self.log.info("A -reindex downloads the chain again, builds the index and turns governance back on") + self.start_node(1, extra_args=self.extra_args[1] + ["-reindex"]) + self.connect_nodes(0, 1) + self.sync_blocks(self.nodes[0:2]) + assert pruned_node.getblockchaininfo()["pruned"] + self.wait_until(lambda: pruned_node.getindexinfo()["govcollateralindex"]["synced"]) + self.bump_mocktime(5 * 60) + + def governance_synced(): + self.bump_mocktime(1) + return pruned_node.mnsync("status")["IsSynced"] + self.wait_until(governance_synced) + self.wait_until(lambda: proposal_hash in pruned_node.gobject("list", "valid", "proposals")) + + self.log.info("The governance collateral index runs and finds collateral during -reindex-chainstate") + node = self.nodes[0] + height = node.getblockcount() + self.restart_node(0, extra_args=self.extra_args[0] + ["-reindex-chainstate"]) + self.wait_until(lambda: node.getblockcount() == height) + self.wait_until(lambda: node.getindexinfo()["govcollateralindex"]["synced"]) + force_finish_mnsync(node) + assert_equal(node.gobject("submit", "0", 1, proposal["createdAt"], proposal["hex"], proposal["collateralHash"]), + proposal_hash) + if __name__ == '__main__': DashGovernanceTest().main() diff --git a/test/functional/feature_governance_cl.py b/test/functional/feature_governance_cl.py index 86b7dc51fde2..54b4ab518e93 100755 --- a/test/functional/feature_governance_cl.py +++ b/test/functional/feature_governance_cl.py @@ -145,8 +145,18 @@ def run_test(self): self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(self.nodes[0:5])) self.log.info("Wait for governance module to catch up with block updates") + tip_height = self.nodes[0].getblockcount() + expected_msg = f'CGovernanceManager::UpdatedBlockTip -- nCachedBlockHeight: {tip_height}' + + def governance_tip_updated(node): + with open(node.debug_log_path, "rb") as dl: + seek_pos = node.debug_log_size(mode="rb") - 100 * 1024 # read the last 100 KiB only + dl.seek(seek_pos if seek_pos > 0 else 0) + debug_log_part = dl.read().decode("utf-8", errors="replace") + return expected_msg in debug_log_part + for node in self.nodes[0:5]: - node.syncwithvalidationinterfacequeue() + self.wait_until(lambda node=node: governance_tip_updated(node)) self.log.info("Bump mocktime to trigger governance cleanup") for delta, expected in ( diff --git a/test/functional/feature_governance_pruned.py b/test/functional/feature_governance_pruned.py deleted file mode 100755 index d5fe42489a06..000000000000 --- a/test/functional/feature_governance_pruned.py +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2026 The Dash Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. -"""Test governance on a pruned node. - -A pruned node can't run -txindex, so it looks proposal collateral up in the governance collateral index. -""" - -import os -import shutil - -from test_framework.governance import EXPECTED_STDERR_GOV_PRUNED_TOO_FAR, prepare_object -from test_framework.messages import uint256_to_string -from test_framework.test_framework import DashTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error, force_finish_mnsync - -MIN_BLOCKS_TO_KEEP = 288 # src/validation.h - - -class GovernancePrunedNodeTest(DashTestFramework): - def add_options(self, parser): - self.add_wallet_options(parser) - - def set_test_params(self): - self.set_dash_test_params(2, 0, [[], ["-prune=550", "-fastprune"]]) - - def run_test(self): - node = self.nodes[0] - pruned_node = self.nodes[1] - assert pruned_node.getblockchaininfo()["pruned"] - assert "txindex" not in pruned_node.getindexinfo() - - # Without InstantSend locks, the miner leaves out the transactions it would otherwise wait on - node.sporkupdate("SPORK_2_INSTANTSEND_ENABLED", 4070908800) - self.wait_for_sporks_same() - - self.log.info("Prepare a proposal on the pruned node") - node.sendtoaddress(pruned_node.getnewaddress(), 10) - self.bump_mocktime(1) - self.generate(node, 1) - self.wait_until(lambda: pruned_node.getbalance() == 10) - proposal_time = self.mocktime - proposal = prepare_object(pruned_node, 1, uint256_to_string(0), proposal_time, 1, "Proposal", 1, pruned_node.getnewaddress()) - self.sync_mempools() - self.bump_mocktime(6) - self.generate(node, 6) - - def submit(): - return pruned_node.gobject("submit", "0", 1, proposal["createdAt"], proposal["hex"], proposal["collateralHash"]) - - self.log.info("The pruned node finds collateral whose block it has pruned") - collateral_height = node.getrawtransaction(proposal["collateralHash"], True)["height"] - # Each -fastprune block file holds dozens of blocks, so mine enough to prune the collateral's whole file - self.bump_mocktime(MIN_BLOCKS_TO_KEEP + 150) - self.generate(node, MIN_BLOCKS_TO_KEEP + 150) - pruned_node.pruneblockchain(pruned_node.getblockcount() - MIN_BLOCKS_TO_KEEP) - assert pruned_node.getblockchaininfo()["pruneheight"] > collateral_height - assert_raises_rpc_error(-1, "Block not available (pruned data)", pruned_node.getblock, - pruned_node.getblockhash(collateral_height)) - proposal_hash = submit() - self.wait_until(lambda: proposal_hash in node.gobject("list", "valid", "proposals")) - - self.log.info("Governance objects survive a restart of the pruned node") - self.restart_node(1) - force_finish_mnsync(pruned_node) - self.connect_nodes(0, 1) - assert proposal_hash in pruned_node.gobject("list", "valid", "proposals") - self.log.info("The reopened index still finds the pruned collateral") - self.wait_until(lambda: pruned_node.getindexinfo()["govcollateralindex"]["synced"]) - assert_equal(submit(), proposal_hash) - - self.log.info("A node that pruned before it had the index starts with governance off instead of failing") - self.stop_node(1) - shutil.rmtree(os.path.join(pruned_node.chain_path, "indexes", "govcollateralindex")) - self.start_node(1) - assert "govcollateralindex" not in pruned_node.getindexinfo() - assert_raises_rpc_error(-1, "Preparing a proposal now would burn its fee", pruned_node.gobject, "prepare", - "0", 1, proposal["createdAt"], proposal["hex"]) - assert_raises_rpc_error(-1, "Governance is disabled on this node", submit) - self.stop_node(1, expected_stderr=EXPECTED_STDERR_GOV_PRUNED_TOO_FAR) - - self.log.info("A -reindex downloads the chain again, builds the index and turns governance back on") - self.start_node(1, extra_args=self.extra_args[1] + ["-reindex"]) - self.connect_nodes(0, 1) - self.sync_blocks() - assert pruned_node.getblockchaininfo()["pruned"] - self.wait_until(lambda: pruned_node.getindexinfo()["govcollateralindex"]["synced"]) - self.bump_mocktime(5 * 60) - - def governance_synced(): - self.bump_mocktime(1) - return pruned_node.mnsync("status")["IsSynced"] - self.wait_until(governance_synced) - self.wait_until(lambda: proposal_hash in pruned_node.gobject("list", "valid", "proposals")) - - self.log.info("The governance collateral index runs and finds collateral during -reindex-chainstate") - height = node.getblockcount() - self.restart_node(0, extra_args=self.extra_args[0] + ["-reindex-chainstate"]) - self.wait_until(lambda: node.getblockcount() == height) - self.wait_until(lambda: node.getindexinfo()["govcollateralindex"]["synced"]) - force_finish_mnsync(node) - assert_equal(node.gobject("submit", "0", 1, proposal["createdAt"], proposal["hex"], proposal["collateralHash"]), - proposal_hash) - - -if __name__ == '__main__': - GovernancePrunedNodeTest().main() diff --git a/test/functional/feature_governance_trigger_voting.py b/test/functional/feature_governance_trigger_voting.py index 84b6ee00c1e5..836d8e43e3a6 100755 --- a/test/functional/feature_governance_trigger_voting.py +++ b/test/functional/feature_governance_trigger_voting.py @@ -52,18 +52,14 @@ def check(): return predicate() self.wait_until(check, timeout=10) - def mine(self, count=1): + def mine(self): nodes = self.online_nodes() - self.bump_mocktime(count, nodes=nodes) - self.generate(self.nodes[0], count, sync_fun=lambda: self.sync_blocks(nodes)) + self.bump_mocktime(1, nodes=nodes) + self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(nodes)) # Masternodes act on a block only from the validation callback for node in nodes: node.syncwithvalidationinterfacequeue() - def mine_to_window_start(self, sb_height): - """Masternodes do nothing before the maturity window, so these blocks need no individual attention.""" - self.mine(sb_height - SB_MATURITY_WINDOW - 1 - self.nodes[0].getblockcount()) - def mine_to(self, height): while self.nodes[0].getblockcount() < height: self.mine() @@ -148,7 +144,8 @@ def create_proposals(self, count): self.sync_mempools(self.online_nodes()) # Collateral transactions without an InstantSend lock are only mined once they are this old self.bump_mocktime(10 * 60 + 1, nodes=self.online_nodes()) - self.mine(GOVERNANCE_FEE_CONFIRMATIONS) + for _ in range(GOVERNANCE_FEE_CONFIRMATIONS): + self.mine() proposals = [] for proposal_hex, collateral, address in prepared: proposal_hash = node.gobject("submit", "0", 1, created_at, proposal_hex, collateral) @@ -228,7 +225,7 @@ def test_single_change_is_snapshot(self): self.log.info("A single change of the approved set: the trigger for the later set is paid") sb_height, (p_kept, p_dropped) = self.start_scenario(2) self.set_approval({p_kept: True, p_dropped: True}) - self.mine_to_window_start(sb_height) + self.mine_to(sb_height - SB_MATURITY_WINDOW - 1) creator, first_trigger = self.create_first_trigger(sb_height) assert_equal(self.trigger_addresses(first_trigger), {self.proposal_address[p_kept], self.proposal_address[p_dropped]}) @@ -266,7 +263,7 @@ def test_creator_votes_after_unfunded_cycle(self, restart): sb_height, (proposal,) = self.start_scenario(1) address = self.proposal_address[proposal] self.set_approval({proposal: True}) - self.mine_to_window_start(sb_height) + self.mine_to(sb_height - SB_MATURITY_WINDOW - 1) creator, trigger = self.create_first_trigger(sb_height) creator_node = self.nodes[creator.nodeIdx] if restart: @@ -289,14 +286,16 @@ def test_creator_votes_after_unfunded_cycle(self, restart): self.log.info("The proposal is approved again: every masternode votes YES on the next trigger and it is paid") next_sb_height = sb_height + SB_CYCLE self.set_approval({proposal: True}) - self.mine_to_window_start(next_sb_height) + self.mine_to(next_sb_height - SB_MATURITY_WINDOW - 1) + def one_trigger_everywhere(): + self.flush_relay() + return all(len(self.triggers_for(n, next_sb_height)) == 1 for n in self.online_nodes()) while True: assert self.nodes[0].getblockcount() < next_sb_height - NO_VOTE_DEADLINE_BLOCKS - 2 self.mine() - if any(self.triggers_for(n, next_sb_height) for n in self.online_nodes()): + if self.wait_until(one_trigger_everywhere, timeout=5, do_assert=False): break - self.wait_relayed(lambda: all(len(self.triggers_for(n, next_sb_height)) == 1 for n in self.online_nodes())) next_trigger = next(iter(self.triggers_for(self.nodes[0], next_sb_height))) # Every masternode knows the trigger and acts on it at this block self.mine() @@ -311,7 +310,7 @@ def test_own_no_vote_is_kept(self): "and another trigger still gets NO") sb_height, (p_main, p_extra) = self.start_scenario(2) self.set_approval({p_main: True, p_extra: True}) - self.mine_to_window_start(sb_height) + self.mine_to(sb_height - SB_MATURITY_WINDOW - 1) window_start = sb_height - SB_MATURITY_WINDOW # The masternode paid at window_start + 3 keeps the approved set {p_main, p_extra} and creates its # trigger once the others are back to {p_main} @@ -357,7 +356,7 @@ def test_yes_vote_survives_tip_below_window(self): sb_height, (p_kept, p_dropped) = self.start_scenario(2) self.set_approval({p_kept: True, p_dropped: True}) window_start = sb_height - SB_MATURITY_WINDOW - self.mine_to_window_start(sb_height) + self.mine_to(window_start - 1) creator, trigger = self.create_first_trigger(sb_height) fork_point = self.nodes[0].getblockhash(window_start - 1) @@ -398,7 +397,7 @@ def test_no_votes_wait_for_deadline(self): f"in the last {NO_VOTE_DEADLINE_BLOCKS} blocks before the superblock") sb_height, (p_a, p_b) = self.start_scenario(2) self.set_approval({p_a: True, p_b: True}) - self.mine_to_window_start(sb_height) + self.mine_to(sb_height - SB_MATURITY_WINDOW - 1) # The masternode paid at sb_height - 5 keeps the approved set {p_a, p_b}: it is stopped until the # block before the one it is paid in, then creates its trigger while catching up late = self.payee(sb_height - 5) diff --git a/test/functional/feature_llmq_chainlocks.py b/test/functional/feature_llmq_chainlocks.py index e279a975d961..409558359beb 100755 --- a/test/functional/feature_llmq_chainlocks.py +++ b/test/functional/feature_llmq_chainlocks.py @@ -88,8 +88,10 @@ def run_test(self): self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash(), timeout=30) self.test_coinbase_best_cl(self.nodes[0]) - self.log.info("Assert that a block below the tip is chainlocked") - assert self.nodes[0].getblock(self.nodes[0].getblockhash(1))['chainlock'] + self.log.info("Assert that all blocks up until the tip are chainlocked") + for h in range(1, self.nodes[0].getblockcount()): + block = self.nodes[0].getblock(self.nodes[0].getblockhash(h)) + assert block['chainlock'] self.log.info(f"Test submitchainlock for too high block") assert_raises_rpc_error(-1, f"No quorum found. Current tip height: {self.nodes[1].getblockcount()}", self.nodes[1].submitchainlock, '0000000000000000000000000000000000000000000000000000000000000000', 'a5c69505b5744524c9ed6551d8a57dc520728ea013496f46baa8a73df96bfd3c86e474396d747a4af11aaef10b17dbe80498b6a2fe81938fe917a3fedf651361bfe5367c800d23d3125820e6ee5b42189f0043be94ce27e73ea13620c9ef6064', self.nodes[1].getblockcount() + 300) @@ -100,9 +102,10 @@ def run_test(self): self.log.info("Generate new blocks and verify that they are not chainlocked") previous_block_hash = self.nodes[0].getbestblockhash() - block_hash = self.generate(self.nodes[0], 1, sync_fun=self.no_op)[0] - self.sleep_and_assert_no_cl(block_hash) - assert self.nodes[0].getblock(previous_block_hash)["chainlock"] + for _ in range(2): + block_hash = self.generate(self.nodes[0], 1, sync_fun=self.no_op)[0] + self.sleep_and_assert_no_cl(block_hash) + assert self.nodes[0].getblock(previous_block_hash)["chainlock"] self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 0) self.wait_for_sporks_same() diff --git a/test/functional/feature_llmq_connections.py b/test/functional/feature_llmq_connections.py index 6d224e809c3b..663586460bd7 100755 --- a/test/functional/feature_llmq_connections.py +++ b/test/functional/feature_llmq_connections.py @@ -10,7 +10,7 @@ ''' -from concurrent.futures import ThreadPoolExecutor +import time from test_framework.test_framework import ( DashTestFramework, @@ -144,9 +144,8 @@ def test_instantsend_after_restart(self): for i in range(num_simple_nodes): self.start_node(i) - with ThreadPoolExecutor(max_workers=len(self.mninfo)) as executor: - for job in [executor.submit(self.start_masternode, mn_info) for mn_info in self.mninfo]: - job.result() + for mn_info in self.mninfo: + self.start_masternode(mn_info) # reconnect: simple nodes to node 0, MNs to node 0 only. # Quorum connections between MNs must be re-established automatically @@ -215,6 +214,11 @@ def check_reconnects(self, expected_connection_count): # Also re-connect non-masternode connections for i in range(1, len(self.nodes)): self.connect_nodes(i, 0) + self.nodes[i].ping() + # wait for ping/pong so that we can be sure that spork propagation works + time.sleep(1) # needed to make sure we don't check before the ping is actually sent (fPingQueued might be true but SendMessages still not called) + for i in range(1, len(self.nodes)): + self.wait_until(lambda: all('pingwait' not in peer for peer in self.nodes[i].getpeerinfo())) def get_mn_connection_count(self, node): peers = node.getpeerinfo() diff --git a/test/functional/feature_llmq_data_recovery.py b/test/functional/feature_llmq_data_recovery.py index 539354eebfbd..435783059061 100755 --- a/test/functional/feature_llmq_data_recovery.py +++ b/test/functional/feature_llmq_data_recovery.py @@ -5,6 +5,7 @@ from contextlib import ExitStack import struct +import time from typing import List, Optional from test_framework.messages import hash256, ser_string from test_framework.p2p import logger @@ -68,6 +69,7 @@ def restart_mns(self, mns=None, exclude=None, reindex=False, qvvec_sync=None, qd self.wait_for_log_line(restarted, log_positions, f"{RECOVERY_TRIGGER_LOG} {block_hash}") self.bump_mocktime(self.quorum_data_thread_request_timeout_seconds + 1) + time.sleep(1) self.sync_blocks() self.wait_for_sporks_same() @@ -101,12 +103,18 @@ def sync_validation(self): for node in self.nodes: node.syncwithvalidationinterfacequeue() + def get_mn(self, protx_hash) -> Optional[MasternodeInfo]: + for mn in self.mninfo: # type: MasternodeInfo + if mn.proTxHash == protx_hash: + return mn + return None + def get_member_mns(self, quorum_type, quorum_hash) -> List[Optional[MasternodeInfo]]: members = self.nodes[0].quorum("info", quorum_type, quorum_hash)["members"] mns = [] for member in members: if member["valid"]: - mns.append(self.get_mninfo(member["proTxHash"])) + mns.append(self.get_mn(member["proTxHash"])) return mns def get_subset_only_in_left(self, quorum_members_left, quorum_members_right) -> List[MasternodeInfo]: @@ -249,6 +257,10 @@ def run_test(self): self.generate(node, 1, sync_fun=self.sync_validation) self.wait_for_chainlocked_block_all_nodes(node.getbestblockhash()) logger.info("Test -llmq-qvvec-sync command line parameter") + # Run with one type separated and then both possible (for regtest) together, both calls generate new quorums + # and are restarting the nodes with the other parameters + self.test_llmq_qvvec_sync([(llmq_test, 0)]) + self.test_llmq_qvvec_sync([(llmq_test_v17, 1)]) self.test_llmq_qvvec_sync([(llmq_test, 0), (llmq_test_v17, 1)]) logger.info("Test invalid command line parameter values") node.stop_node() diff --git a/test/functional/feature_llmq_is_retroactive.py b/test/functional/feature_llmq_is_retroactive.py index 5b182ce20341..6ab716bfa103 100755 --- a/test/functional/feature_llmq_is_retroactive.py +++ b/test/functional/feature_llmq_is_retroactive.py @@ -110,6 +110,7 @@ def run_test(self): block = self.generatetoaddress(self.nodes[3], 1, self.nodes[0].getnewaddress(), sync_fun=self.no_op)[0] self.reconnect_isolated_node(3, 0) self.wait_for_chainlocked_block_all_nodes(block) + self.nodes[0].setmocktime(self.mocktime) self.log.info("testing retroactive signing with partially known TX") self.isolate_node(3) diff --git a/test/functional/feature_llmq_signing.py b/test/functional/feature_llmq_signing.py index 3fd5769e78fb..1f0d3827f17c 100755 --- a/test/functional/feature_llmq_signing.py +++ b/test/functional/feature_llmq_signing.py @@ -63,12 +63,15 @@ def check_sigs(hasrecsigs, isconflicting1, isconflicting2, sig_id=None): def wait_for_sigs(hasrecsigs, isconflicting1, isconflicting2, timeout): self.wait_until(lambda: check_sigs(hasrecsigs, isconflicting1, isconflicting2), timeout = timeout) - def assert_sigs_nochange(hasrecsigs, isconflicting1, isconflicting2, timeout): - assert not self.wait_until(lambda: not check_sigs(hasrecsigs, isconflicting1, isconflicting2), timeout = timeout, do_assert = False) + def assert_sigs_nochange(hasrecsigs, isconflicting1, isconflicting2, timeout, other_ids=()): + def unchanged(): + return all(check_sigs(hasrecsigs, isconflicting1, isconflicting2, sig_id) for sig_id in (id, *other_ids)) + assert not self.wait_until(lambda: not unchanged(), timeout = timeout, do_assert = False) # Recovering, conflicting or removing a recovered sig can't be undone during this test without a - # deliberate step, so a change caused by any earlier step is still visible in a later check. A step - # that must cause no change is therefore checked at once. + # deliberate step, so a change caused by any earlier step is still visible in a later window. A step + # that must cause no change is therefore checked at once, and its window is shared with the next + # step that must cause no change either. # Initial state wait_for_sigs(False, False, False, 1) @@ -152,6 +155,7 @@ def assert_sigs_nochange(hasrecsigs, isconflicting1, isconflicting2, timeout): # Mine one more quorum, so that we have 2 active ones, nothing should change self.mine_quorum() + # The window for this is shared with the one after the next quorums below assert check_sigs(True, False, True) first_id = id @@ -178,10 +182,10 @@ def assert_sigs_nochange(hasrecsigs, isconflicting1, isconflicting2, timeout): recsig_time = self.mocktime - # The quorum that signed is inactive now, which must not affect the recovered sigs: they only age out by time. - # mine_quorum does not wait for the recovered signature to reach every masternode. - wait_for_sigs(True, False, True, 15) - assert check_sigs(True, False, True, sig_id=first_id) + # Mine 2 more quorums, so that the one used for the the recovered sig should become inactive, nothing should change + self.mine_quorum() + self.mine_quorum() + assert_sigs_nochange(True, False, True, 3, other_ids=[first_id]) # fast forward until 0.5 days before cleanup is expected, recovered sig should still be valid self.bump_mocktime(recsig_time + int(60 * 60 * 24 * 6.5) - self.mocktime, update_schedulers=False) diff --git a/test/functional/feature_llmq_simplepose.py b/test/functional/feature_llmq_simplepose.py index 4e670b934387..ccb98207493b 100755 --- a/test/functional/feature_llmq_simplepose.py +++ b/test/functional/feature_llmq_simplepose.py @@ -30,18 +30,34 @@ def run_test(self): self.test_cloned_contributions() - # Lets isolate MNs one by one and verify that punishment/banning happens - self.test_banning(self.isolate_mn, 2) - - self.repair_masternodes(False) + if not self.options.disable_spork23: + # Lets isolate MNs one by one and verify that punishment/banning happens + self.test_banning(self.isolate_mn, 2) + + self.repair_masternodes(False) + else: + # The contribution-miss ban path (MarkBadMember -> PoSePunish) is not + # gated on spork23 (spork23 only gates connection/proto-version checks + # and probes), so it behaves identically with spork23 disabled and is + # already covered by the spork23-enabled run of this test. + self.log.info("Skipping contribution-miss banning, not affected by spork23") + # Mine one quorum in normal conditions so that the sections below start + # from the same state as in the spork23-enabled run: an existing quorum + # and all masternodes healthy. + self.reset_probe_timeouts() + self.mine_quorum() self.nodes[0].sporkupdate("SPORK_21_QUORUM_ALL_CONNECTED", 0) self.wait_for_sporks_same() self.reset_probe_timeouts() - # Lets restart masternodes with closed ports and verify that they get banned even though they are connected to other MNs (via outbound connections) - self.test_banning(self.close_mn_port, count=1) + if not self.options.disable_spork23: + # Lets restart masternodes with closed ports and verify that they get banned even though they are connected to other MNs (via outbound connections) + self.test_banning(self.close_mn_port) + else: + # With PoSe off there should be no punishing for non-reachable nodes + self.test_no_banning(self.close_mn_port, 3) self.repair_masternodes(True) diff --git a/test/functional/feature_llmq_simplepose_capabilities.py b/test/functional/feature_llmq_simplepose_capabilities.py index 627038a261ff..3f54a8592cc3 100755 --- a/test/functional/feature_llmq_simplepose_capabilities.py +++ b/test/functional/feature_llmq_simplepose_capabilities.py @@ -41,13 +41,8 @@ class LLMQSimplePoSeCapabilitiesTest(SimplePoSeMixin, DashTestFramework): def set_test_params(self): self.set_simplepose_test_params() - def add_options(self, parser): - super().add_options(parser) - parser.add_argument("--disable-spork23", dest="disable_spork23", default=False, action="store_true", - help="Test with spork23 disabled") - def run_test(self): - self.set_pose_sporks(pose_enabled=not self.options.disable_spork23) + self.set_pose_sporks() # These scenarios need SPORK_21 on, an existing quorum and all masternodes healthy self.nodes[0].sporkupdate("SPORK_21_QUORUM_ALL_CONNECTED", 0) @@ -58,10 +53,8 @@ def run_test(self): if not self.options.disable_spork23: self.test_banning(self.force_old_mn_proto, 3) else: - self.log.info("With PoSe off there should be no punishing for outdated nodes") - self.force_old_mn_proto(self.mninfo[0]) - self.mine_quorum(expected_connections=3) - assert not check_punished(self.nodes[0], self.mninfo[0]) + # With PoSe off there should be no punishing for outdated nodes + self.test_no_banning(self.force_old_mn_proto, 3) self.repair_masternodes(True) self.reset_probe_timeouts() @@ -86,9 +79,8 @@ def test_no_service(self, relay, services, reason, banned): node = mn.get_node(self) others = [m for m in self.mninfo if m is not mn] expected_complaints = len(others) if banned else 0 - rounds = 2 if banned else 1 - for i in range(rounds): - self.log.info(f"Testing PoSe {'banning' if banned else 'no banning'} of a masternode that {reason} {i + 1}/{rounds}") + for i in range(2): + self.log.info(f"Testing PoSe {'banning' if banned else 'no banning'} of a masternode that {reason} {i + 1}/2") self.reset_probe_timeouts() with others[0].get_node(self).assert_debug_log([reason] if banned else [], unexpected_msgs=[] if banned else [reason]): self.mine_quorum_no_service(mn, others, relay, services, expected_complaints) diff --git a/test/functional/feature_llmq_singlenode.py b/test/functional/feature_llmq_singlenode.py index 45cb99f9f223..0238ddced9b2 100755 --- a/test/functional/feature_llmq_singlenode.py +++ b/test/functional/feature_llmq_singlenode.py @@ -18,6 +18,7 @@ from test_framework.util import ( assert_raises_rpc_error, assert_greater_than, + wait_until_helper, ) @@ -60,6 +61,9 @@ def check_sigs(self, hasrecsigs, isconflicting1, isconflicting2): def wait_for_sigs(self, hasrecsigs, isconflicting1, isconflicting2, timeout): self.wait_until(lambda: self.check_sigs(hasrecsigs, isconflicting1, isconflicting2), timeout = timeout) + def assert_sigs_nochange(self, hasrecsigs, isconflicting1, isconflicting2, timeout): + assert not wait_until_helper(lambda: not self.check_sigs(hasrecsigs, isconflicting1, isconflicting2), timeout = timeout, do_assert = False) + def log_connections(self): connections = [] @@ -96,7 +100,7 @@ def run_test(self): # Sign second share and test optional quorumHash parameter, should not result in recovered sig # 1. Providing an invalid quorum hash should fail and cause no changes for sigs assert not self.mninfo[1].get_node(self).quorum("sign", q_type, id, msgHash, msgHash) - assert self.check_sigs(False, False, False) + self.assert_sigs_nochange(False, False, False, 3) # 2. Providing a valid quorum hash should succeed and cause no changes for sigss quorumHash = self.mninfo[1].get_node(self).quorum("selectquorum", q_type, id)["quorumHash"] @@ -114,6 +118,10 @@ def run_test(self): self.mninfo[1].get_node(self).quorum("sign", q_type, id, msgHash) self.wait_for_sigs(True, False, True, 15) + has0 = self.nodes[0].quorum("hasrecsig", q_type, id, msgHash) + has1 = self.nodes[1].quorum("hasrecsig", q_type, id, msgHash) + has2 = self.nodes[2].quorum("hasrecsig", q_type, id, msgHash) + assert (has0 or has1 or has2) self.log.info("Test `quorum verify` rpc") node = self.mninfo[0].get_node(self) @@ -133,7 +141,13 @@ def run_test(self): self.log.info("Mine one more quorum, so that we have 2 active ones, nothing should change") self.mine_quorum_single_member() - assert self.check_sigs(True, False, True) + self.assert_sigs_nochange(True, False, True, 3) + + + self.log.info("Mine 2 more quorums, so that the one used for the the recovered sig should become inactive, nothing should change") + self.mine_quorum_single_member() + self.mine_quorum_single_member() + self.assert_sigs_nochange(True, False, True, 3) self.log_connections() self.log.info("Fast forward until 0.5 days before cleanup is expected, recovered sig should still be valid") diff --git a/test/functional/feature_protx_version.py b/test/functional/feature_protx_version.py index 7b25f0aa60af..f6d7adaf15ef 100755 --- a/test/functional/feature_protx_version.py +++ b/test/functional/feature_protx_version.py @@ -30,7 +30,6 @@ def add_options(self, parser): self.add_wallet_options(parser) def set_test_params(self): - self.noban_tx_relay = True self.extra_args = [[ '-deprecatedrpc=legacy_mn', '-testactivationheight=v19@200', @@ -139,8 +138,11 @@ def run_test(self): payout_mn = new_mn # mine more quorums and make sure everything still works between v19 and v24 - self.mine_quorum() - self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) + prev_quorum = None + for _ in range(2): + quorum = self.mine_quorum() + assert prev_quorum != quorum + self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) self.test_protx_v24_versioning(new_mn, migrate_legacy_mn, surviving_legacy_mn, basic_mn, payout_mn, evo_info_0) diff --git a/test/functional/feature_stats.py b/test/functional/feature_stats.py index 43375d352bac..7cafd7fb6a6c 100755 --- a/test/functional/feature_stats.py +++ b/test/functional/feature_stats.py @@ -138,7 +138,6 @@ def test_conn(self, host: str): server.start() self.restart_node(0, extra_args=[f'-statshost=udp://{host}', '-statsbatchsize=0', '-statsduration=0', '-statsperiod=5', '-reindex']) server.assert_msg_received("CheckBlock_us") - self.nodes[0].mockscheduler(5) server.assert_msg_received("network.difficulty:") wallet = MiniWallet(self.nodes[0]) utxo = wallet.get_utxo() diff --git a/test/functional/interface_zmq_dash.py b/test/functional/interface_zmq_dash.py index ddb5f7c64009..bbb9428e2e62 100755 --- a/test/functional/interface_zmq_dash.py +++ b/test/functional/interface_zmq_dash.py @@ -144,12 +144,21 @@ def run_test(self): self.sync_blocks() self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) + # Wait a moment to avoid subscribing to recovered sig in the test before the one from the chainlock + # has been sent which leads to test failure. + time.sleep(1) # Test all dash related ZMQ publisher self.test_recovered_signature_publishers() self.test_chainlock_publishers() self.test_governance_publishers() self.test_getzmqnotifications() self.test_instantsend_publishers() + self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) + self.test_instantsend_publishers() + # At this point, we need to move forward 3 cycles (3 x 24 blocks) so the first 3 quarters can be created (without DKG sessions) + self.generate(self.nodes[0], 24) + self.mine_cycle_quorum() + self.test_instantsend_publishers() finally: # Destroy the ZMQ context. self.log.debug("Destroying ZMQ context") @@ -176,13 +185,9 @@ def validate_recovered_sig(request_id, msg_hash): # Make sure the recovered sig exists by RPC self.wait_for_recovered_sig(request_id, msg_hash) rpc_recovered_sig = self.mninfo[0].get_node(self).quorum('getrecsig', 100, request_id, msg_hash) - # The recovered sig of an earlier ChainLock may still be published after subscribing, skip it. # Validate hashrecoveredsig - hash_subscriber = self.subscribers[ZMQPublisher.hash_recovered_sig] - while True: - topic, body, _ = hash_subscriber.socket.recv_multipart() - if topic == hash_subscriber.topic and body.hex() == msg_hash: - break + zmq_recovered_sig_hash = self.subscribers[ZMQPublisher.hash_recovered_sig].receive().read(32).hex() + assert_equal(zmq_recovered_sig_hash, msg_hash) # Validate rawrecoveredsig zmq_recovered_sig_raw = CRecoveredSig() zmq_recovered_sig_raw.deserialize(self.subscribers[ZMQPublisher.raw_recovered_sig].receive()) diff --git a/test/functional/mining_getblocktemplate_longpoll.py b/test/functional/mining_getblocktemplate_longpoll.py index e089c97cb491..84370fb6cdad 100755 --- a/test/functional/mining_getblocktemplate_longpoll.py +++ b/test/functional/mining_getblocktemplate_longpoll.py @@ -2,16 +2,14 @@ # Copyright (c) 2014-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 longpolling with getblocktemplate. - -The mempool-triggered return, which needs a real minute, is in -mining_getblocktemplate_longpoll_mempool.py. -""" +"""Test longpolling with getblocktemplate.""" +import random import threading from test_framework.test_framework import BitcoinTestFramework from test_framework.util import get_rpc_proxy +from test_framework.wallet import MiniWallet class LongpollThread(threading.Thread): @@ -33,6 +31,7 @@ def set_test_params(self): self.supports_cli = False def run_test(self): + self.log.info("Warning: this test will take about 70 seconds in the best case. Be patient.") self.log.info("Test that longpollid doesn't change between successive getblocktemplate() invocations if nothing else happens") self.generate(self.nodes[0], 10) template = self.nodes[0].getblocktemplate() @@ -51,6 +50,7 @@ def run_test(self): thr.join(5) # wait 5 seconds or until thread exits assert thr.is_alive() + self.miniwallet = MiniWallet(self.nodes[0]) self.log.info("Test that longpoll will terminate if another node generates a block") self.generate(self.nodes[1], 1) # generate a block on another node # check that thread will exit now that new transaction entered mempool @@ -65,5 +65,18 @@ def run_test(self): thr.join(5) # wait 5 seconds or until thread exits assert not thr.is_alive() + self.log.info("Test that introducing a new transaction into the mempool will terminate the longpoll") + thr = LongpollThread(self.nodes[0]) + with self.nodes[0].assert_debug_log(["Received a POST request for / from"], timeout=3): + thr.start() + # generate a transaction and submit it + self.miniwallet.send_self_transfer(from_node=random.choice(self.nodes)) + # after one minute, every 10 seconds the mempool is probed, so in 80 seconds it should have returned + + def check(): + self.bump_mocktime(1) + return not thr.is_alive() + self.wait_until(check, timeout=60 + 20) + if __name__ == '__main__': GetBlockTemplateLPTest().main() diff --git a/test/functional/mining_getblocktemplate_longpoll_mempool.py b/test/functional/mining_getblocktemplate_longpoll_mempool.py deleted file mode 100755 index e904ef44d48c..000000000000 --- a/test/functional/mining_getblocktemplate_longpoll_mempool.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2014-2020 The Bitcoin Core developers -# Copyright (c) 2026 The Dash Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. -"""Test that a getblocktemplate longpoll returns once the mempool changes. - -The RPC only looks at the mempool after a minute on the steady clock, which -mocktime can't shorten, so this takes about 70 seconds. -""" - -import random - -from mining_getblocktemplate_longpoll import LongpollThread -from test_framework.test_framework import BitcoinTestFramework -from test_framework.wallet import MiniWallet - - -class GetBlockTemplateLPMempoolTest(BitcoinTestFramework): - def set_test_params(self): - self.num_nodes = 2 - self.supports_cli = False - - def run_test(self): - self.generate(self.nodes[0], 10) - miniwallet = MiniWallet(self.nodes[0]) - - self.log.info("Test that introducing a new transaction into the mempool will terminate the longpoll") - thr = LongpollThread(self.nodes[0]) - with self.nodes[0].assert_debug_log(["Received a POST request for / from"], timeout=3): - thr.start() - miniwallet.send_self_transfer(from_node=random.choice(self.nodes)) - # after one minute, every 10 seconds the mempool is probed, so in 80 seconds it should have returned - - def check(): - self.bump_mocktime(1) - return not thr.is_alive() - self.wait_until(check, timeout=60 + 20) - - -if __name__ == '__main__': - GetBlockTemplateLPMempoolTest().main() diff --git a/test/functional/p2p_dstx.py b/test/functional/p2p_dstx.py index 8605699a2286..5814037f518d 100755 --- a/test/functional/p2p_dstx.py +++ b/test/functional/p2p_dstx.py @@ -132,12 +132,8 @@ def run_test(self): peer_unbalanced.send_and_ping(msg_dstx(unbalanced)) self.log.info("Mine to the last pre-V24 block") - # Advance the last blocks one at a time so we stop on the exact boundary tip: v24 rules - # are enforced for the next block but not yet at our tip. - batch = V24_ACTIVATION_HEIGHT - 10 - node.getblockcount() - self.bump_mocktime(156 * batch, update_schedulers=False) - self.generate(node, batch) - assert not softfork_active(node, "v24") + # Advance one block at a time so we stop on the exact boundary tip: v24 rules are + # enforced for the next block but not yet at our tip. while not softfork_active(node, "v24"): self.bump_mocktime(156) self.generate(node, 1) diff --git a/test/functional/p2p_platform_ban.py b/test/functional/p2p_platform_ban.py index 28e7c0c76256..405d6e7866f6 100755 --- a/test/functional/p2p_platform_ban.py +++ b/test/functional/p2p_platform_ban.py @@ -13,12 +13,16 @@ import struct +class PlatformBanInterface(P2PInterface): + def __init__(self): + super().__init__() + + class PlatformBanMessagesTest(DashTestFramework): def add_options(self, parser): self.add_wallet_options(parser) def set_test_params(self): - self.noban_tx_relay = True self.set_dash_test_params(1, 0, [[]], evo_count=3) def skip_test_if_missing_module(self): @@ -43,6 +47,8 @@ def run_test(self): # regardless of where in the cycle the tip is self.generate(self.nodes[0], 10, sync_fun=self.no_op) + self.mempool_size = 0 + self.mine_quorum(llmq_type_name='llmq_test_platform', llmq_type=106) self.log.info("Create and sign platform-ban message for mn-0") @@ -62,7 +68,7 @@ def run_test(self): msg.sig = bytearray.fromhex(recsig["sig"]) self.log.info("Platform ban message is created and signed") - p2p_node2 = self.mninfo[2].get_node(self).add_p2p_connection(P2PInterface()) + p2p_node2 = self.mninfo[2].get_node(self).add_p2p_connection(PlatformBanInterface()) p2p_node2.send_message(msg) wait_until_helper(lambda: p2p_node2.message_count["platformban"] > 0, timeout=10, lock=p2p_lock) p2p_node2.message_count["platformban"] = 0 @@ -77,7 +83,7 @@ def run_test(self): mninfos_valid = self.mninfo.copy()[1:] self.mine_quorum(llmq_type_name='llmq_test_platform', expected_members=2, expected_connections=1, expected_contributions=2, expected_commitments=2, llmq_type=106, mninfos_valid=mninfos_valid) - p2p_node = node.add_p2p_connection(P2PInterface()) + p2p_node = node.add_p2p_connection(PlatformBanInterface()) p2p_node.send_message(msg) self.mine_quorum(llmq_type_name='llmq_test_platform', expected_members=2, expected_connections=1, expected_contributions=2, expected_commitments=2, llmq_type=106, mninfos_valid=mninfos_valid) assert self.check_banned(self.mninfo[0]) diff --git a/test/functional/p2p_quorum_data.py b/test/functional/p2p_quorum_data.py index 99a79ff83be8..f87967b4e215 100755 --- a/test/functional/p2p_quorum_data.py +++ b/test/functional/p2p_quorum_data.py @@ -5,6 +5,7 @@ import copy import struct +import time from test_framework.messages import ( CSigSharesInv, @@ -121,16 +122,10 @@ def get_score(): if peer["id"] == peer_id: return peer["banscore"] return None - if expected_score is None: - # A peer that reached the ban threshold is dropped asynchronously - wait_until_helper(lambda: get_score() is None, timeout=10) - return - # Scores are bumped while a message is processed and a pong is only sent after every earlier message was - # processed, so once each connection answered a ping the score is final. Connections of banned peers are - # not pinged, they are waited for to be closed where one is expected. - for p2p in node.p2ps: - if p2p.is_connected: - p2p.sync_with_ping() + wait_until_helper(lambda: get_score() == expected_score, timeout=6) + # Re-read after a settle delay: the first read can race a pending bump, + # in particular when the expected score is the peer's current one (e.g. 0). + time.sleep(0.1) assert_equal(get_score(), expected_score) @@ -172,11 +167,8 @@ def test_qgetdata(self, qgetdata, expected_error=0, len_vvec=0, len_contribution assert_qdata(self.get_qdata(), qgetdata, expected_error, len_vvec, len_contributions) def wait_for_qmessage(self, message=None, timeout=3, message_expected=True): - if message_expected: - wait_until_helper(lambda: self.message_count[message] > 0, timeout=timeout, lock=p2p_lock) - else: - # A reply would have been sent before the pong - self.sync_with_ping() + wait_until_helper(lambda: self.message_count[message] > 0, timeout=timeout, lock=p2p_lock, do_assert=message_expected) + if not message_expected: assert self.message_count[message] == 0 self.message_count[message] = 0 @@ -217,6 +209,10 @@ def test_basics(): id_p2p_node0 = get_p2p_id(node0) id_p2p_mn2 = get_p2p_id(mn2.get_node(self)) + # Ensure that both nodes start with zero ban score + wait_for_banscore(node0, id_p2p_node0, 0) + wait_for_banscore(mn2.get_node(self), id_p2p_mn2, 0) + self.log.info("Check that normal node doesn't respond to qgetdata " "and does bump our score") p2p_node0.test_qgetdata(qgetdata_all, response_expected=False) @@ -259,6 +255,7 @@ def test_basics(): id_p2p_mn2 = get_p2p_id(mn2.get_node(self)) mnauth(mn1.get_node(self), id_p2p_mn1, fake_mnauth_1[0], fake_mnauth_1[1]) mnauth(mn2.get_node(self), id_p2p_mn2, fake_mnauth_2[0], fake_mnauth_2[1]) + wait_for_banscore(mn1.get_node(self), id_p2p_mn1, 0) p2p_mn2.test_qgetdata(qgetdata_all, 0, self.llmq_threshold, self.llmq_size) qdata_valid = p2p_mn2.get_qdata() # - Not requested @@ -320,8 +317,6 @@ def send_bad_qdata_expect_disconnect(bad_qdata): mn1.get_node(self).disconnect_p2ps() mn2.get_node(self).disconnect_p2ps() - # Neither the error replies nor the recovery depend on how expired requests are removed - def test_error_codes_and_recovery(): self.log.info("Test all available error codes") p2p_mn2 = p2p_connection(mn2.get_node(self)) id_p2p_mn2 = get_p2p_id(mn2.get_node(self)) @@ -397,6 +392,7 @@ def test_qgetdata_rejects_requester_error(): p2p_mn = p2p_connection(mn2.get_node(self)) id_p2p_mn = get_p2p_id(mn2.get_node(self)) mnauth(mn2.get_node(self), id_p2p_mn, fake_mnauth_2[0], fake_mnauth_2[1]) + wait_for_banscore(mn2.get_node(self), id_p2p_mn, 0) p2p_mn.send_message(msg_qgetdata(quorum_hash_int, 100, 0x01, error=error)) self.wait_until(lambda: not p2p_mn.is_connected, timeout=10) mn2.get_node(self).disconnect_p2ps() @@ -411,8 +407,6 @@ def test_send_from_two_to_one(send_1, expected_score_1, send_2, expected_score_2 p2p_mn3_1.test_qgetdata(qgetdata_vvec, 0, self.llmq_threshold, 0) if send_2: p2p_mn3_2.test_qgetdata(qgetdata_vvec, 0, self.llmq_threshold, 0) - if expected_score_2 is None: - self.wait_until(lambda: not p2p_mn3_2.is_connected, timeout=10) wait_for_banscore(mn3.get_node(self), id_p2p_mn3_1, expected_score_1) wait_for_banscore(mn3.get_node(self), id_p2p_mn3_2, expected_score_2) @@ -452,6 +446,8 @@ def test_send_from_two_to_one(send_1, expected_score_1, send_2, expected_score_2 test_send_from_two_to_one(False, 75, True, None) # mn1 should still have a score of 75 wait_for_banscore(mn3.get_node(self), id_p2p_mn3_1, 75) + # mn2 should be "banned" now + self.wait_until(lambda: not p2p_mn3_2.is_connected, timeout=10) mn3.get_node(self).disconnect_p2ps() # Test that QWATCH connections are also allowed to query data but all @@ -465,6 +461,9 @@ def test_qwatch_connections(): id_p2p_mn3_2 = get_p2p_id(mn3.get_node(self), uacomment_m3_2) assert id_p2p_mn3_1 != id_p2p_mn3_2 + wait_for_banscore(mn3.get_node(self), id_p2p_mn3_1, 0) + wait_for_banscore(mn3.get_node(self), id_p2p_mn3_2, 0) + # Send QWATCH for both connections p2p_mn3_1.send_message(msg_qwatch()) p2p_mn3_2.send_message(msg_qwatch()) @@ -550,10 +549,10 @@ def test_qsigshares_inv_oom(): test_basics() test_request_limit() test_qwatch_connections() + test_watchquorums() + test_rpc_quorum_getdata_protx_hash() - test_error_codes_and_recovery() - test_watchquorums() - test_rpc_quorum_getdata_protx_hash() + # Once: nError rejection does not depend on request-expiry cleanup. test_qgetdata_rejects_requester_error() test_qsigshares_inv_oom() diff --git a/test/functional/rpc_mnauth.py b/test/functional/rpc_mnauth.py index 11a7c85db428..d09ef4e022fd 100755 --- a/test/functional/rpc_mnauth.py +++ b/test/functional/rpc_mnauth.py @@ -6,7 +6,8 @@ from test_framework.messages import hash256 from test_framework.p2p import P2PInterface from test_framework.test_framework import ( - BitcoinTestFramework, + DashTestFramework, + MasternodeInfo, ) from test_framework.util import assert_equal, assert_raises_rpc_error @@ -17,16 +18,20 @@ ''' -class FakeMNAUTHTest(BitcoinTestFramework): +class FakeMNAUTHTest(DashTestFramework): + def add_options(self, parser): + self.add_wallet_options(parser) + def set_test_params(self): - self.num_nodes = 1 + self.set_dash_test_params(2, 1) def run_test(self): - node = self.nodes[0] + masternode: MasternodeInfo = self.mninfo[0] + node = masternode.get_node(self) node.add_p2p_connection(P2PInterface()) - protx_hash = "01" + "0" * 62 - public_key = node.bls("generate")["public"] + protx_hash = masternode.proTxHash + public_key = masternode.pubKeyOperator # The peerinfo should not yet contain verified_proregtx_hash/verified_pubkey_hash assert "verified_proregtx_hash" not in node.getpeerinfo()[-1] diff --git a/test/functional/rpc_netinfo.py b/test/functional/rpc_netinfo.py index 8c8b8a124c4a..d6f84336beb0 100755 --- a/test/functional/rpc_netinfo.py +++ b/test/functional/rpc_netinfo.py @@ -230,6 +230,8 @@ def run_test(self): # Need to destroy masternodes as the next test will be re-creating them self.node_evo.destroy_mn(self) self.node_two.destroy_mn(self) + self.restart_node(self.node_evo.mn.nodeIdx, extra_args=evo_extra_args) + self.reconnect_nodes() self.log.info("Test unique properties map duplication checks") self.test_uniqueness() diff --git a/test/functional/rpc_quorum.py b/test/functional/rpc_quorum.py index 19c39f0033dc..14e8e277f706 100755 --- a/test/functional/rpc_quorum.py +++ b/test/functional/rpc_quorum.py @@ -39,6 +39,7 @@ def run_test(self): assert_equal(node.quorum("dkginfo", other)["active_dkgs"], sum(not d["known"] for d in other_upcoming)) self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0) self.wait_for_sporks_same() + self.mine_until_mns_confirmed_for_next_dkg() quorum_hash = self.mine_quorum_single_member() quorum_info = self.nodes[0].quorum("info", 100, quorum_hash) diff --git a/test/functional/rpc_verifychainlock.py b/test/functional/rpc_verifychainlock.py index f70151ef3ac6..32c13db98e00 100755 --- a/test/functional/rpc_verifychainlock.py +++ b/test/functional/rpc_verifychainlock.py @@ -35,6 +35,7 @@ def run_test(self): node1 = self.nodes[1] self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0) self.wait_for_sporks_same() + self.mine_until_mns_confirmed_for_next_dkg() self.mine_quorum_single_member() self.wait_for_chainlocked_block(node0, self.generate(node0, 1, sync_fun=self.no_op)[0]) chainlock = node0.getbestchainlock() diff --git a/test/functional/rpc_verifyislock.py b/test/functional/rpc_verifyislock.py index e4fb281d8f92..ac2a062a3a29 100755 --- a/test/functional/rpc_verifyislock.py +++ b/test/functional/rpc_verifyislock.py @@ -37,6 +37,8 @@ def run_test(self): self.wait_for_sporks_same() self.mine_cycle_quorum() + self.bump_mocktime(1) + self.generate(self.nodes[0], 8, sync_fun=self.sync_blocks) txid = node.sendtoaddress(node.getnewaddress(), 1) self.wait_for_instantlock(txid, nodes=[node]) @@ -59,6 +61,8 @@ def run_test(self): # Mined, should ignore higher maxHeight assert node.verifyislock(request_id, txid, rec_sig, node.getblockcount() + 100) + # Mine one more cycle of rotated quorums + self.mine_cycle_quorum() # Create an ISLOCK using an active quorum which will be replaced when a new cycle happens request_id = None utxos = node.listunspent() diff --git a/test/functional/test_framework/asset_locks.py b/test/functional/test_framework/asset_locks.py deleted file mode 100644 index a9993b88d105..000000000000 --- a/test/functional/test_framework/asset_locks.py +++ /dev/null @@ -1,210 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2022-2026 The Dash Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. -"""Shared setup and Asset Lock / Asset Unlock helpers for the feature_asset_locks*.py tests.""" - -import copy -import struct -from decimal import Decimal -from io import BytesIO - -from test_framework.authproxy import JSONRPCException -from test_framework.messages import ( - CAssetLockTx, - CAssetUnlockTx, - COIN, - COutPoint, - CTransaction, - CTxIn, - CTxOut, - tx_from_hex, - hash256, - ser_string, -) -from test_framework.script import ( - CScript, - OP_RETURN, -) -from test_framework.script_util import ( - key_to_p2pk_script, - key_to_p2pkh_script, -) -from test_framework.util import ( - assert_equal, - assert_greater_than, -) - -llmq_type_test = 106 # LLMQType::LLMQ_TEST_PLATFORM -MNEHF_SIGNAL_TX_TYPE = 7 # TRANSACTION_MNHF_SIGNAL -tiny_amount = int(Decimal("0.0007") * COIN) -blocks_in_one_day = 100 -HEIGHT_DIFF_EXPIRING = 48 - - -class AssetLocksMixin: - """Mixed into the DashTestFramework subclasses of the feature_asset_locks*.py tests""" - def set_asset_locks_test_params(self, extra_args=None): - extra_args = extra_args or [] - self.set_dash_test_params(2, 0, [[ - "-whitelist=127.0.0.1", - "-llmqtestinstantsenddip0024=llmq_test_instantsend", - "-acceptnonstdtxn=1", - ] + extra_args] * 2, evo_count=2) - - def add_options(self, parser): - self.add_wallet_options(parser) - - def create_assetlock(self, coin, amount, pubkey, version=1): - node_wallet = self.nodes[0] - - - coins = coin if isinstance(coin, list) else [coin] - inputs = [CTxIn(COutPoint(int(c["txid"], 16), c["vout"])) for c in coins] - - credit_outputs = [] - tmp_amount = amount - if tmp_amount > COIN: - tmp_amount -= COIN - credit_outputs.append(CTxOut(COIN, key_to_p2pkh_script(pubkey))) - credit_outputs.append(CTxOut(tmp_amount, key_to_p2pkh_script(pubkey))) - - lockTx_payload = CAssetLockTx(version, credit_outputs) - - remaining = sum(int(COIN * c['amount']) for c in coins) - tiny_amount - amount - - tx_output_ret = CTxOut(amount, CScript([OP_RETURN, b""])) - tx_output = CTxOut(remaining, key_to_p2pk_script(pubkey)) - - lock_tx = CTransaction() - lock_tx.vin = inputs - lock_tx.vout = [tx_output, tx_output_ret] if remaining > 0 else [tx_output_ret] - lock_tx.nVersion = 3 - lock_tx.nType = 8 # asset lock type - lock_tx.vExtraPayload = lockTx_payload.serialize() - - lock_tx = node_wallet.signrawtransactionwithwallet(lock_tx.serialize().hex()) - return tx_from_hex(lock_tx["hex"]) - - def create_assetunlock_request_id(self, index): - # request ID = sha256("plwdtx", index) - request_id_buf = ser_string(b"plwdtx") + struct.pack(" 0: - self.log.info(f"Generating batch of blocks {count} left") - batch = min(50, count) - count -= batch - self.bump_mocktime(10 * 60 + 1) - self.generate(self.nodes[1], batch, sync_fun=sync_fun) - - # This functional test intentionally setup only 2 MN and only 2 Evo nodes - # to ensure that corner case of quorum with minimum amount of nodes as possible - # does not cause any issues in Dash Core - def mine_quorum_2_nodes(self): - self.mine_quorum(llmq_type_name='llmq_test_platform', expected_members=2, expected_connections=1, expected_contributions=2, expected_commitments=2, llmq_type=106) - - def create_asset_unlock_child(self, node_wallet, asset_unlock_tx, asset_unlock_txid): - child_value = Decimal(asset_unlock_tx.vout[0].nValue - tiny_amount) / COIN - child_hex = node_wallet.createrawtransaction( - [{'txid': asset_unlock_txid, 'vout': 0}], - {node_wallet.getnewaddress(): child_value}) - signed_child = node_wallet.signrawtransactionwithwallet(child_hex) - assert signed_child['complete'] - child_txid = node_wallet.sendrawtransaction(signed_child['hex']) - - # Ensure package selection considers the child before its Asset Unlock - # ancestor is considered on its own. - node_wallet.prioritisetransaction(child_txid, COIN) - return child_txid diff --git a/test/functional/test_framework/simplepose.py b/test/functional/test_framework/simplepose.py index bbd8b3c9e4fa..286c8d1b627d 100644 --- a/test/functional/test_framework/simplepose.py +++ b/test/functional/test_framework/simplepose.py @@ -21,13 +21,25 @@ def set_simplepose_test_params(self): def add_options(self, parser): self.add_wallet_options(parser) + parser.add_argument("--disable-spork23", dest="disable_spork23", default=False, action="store_true", + help="Test with spork23 disabled") - def set_pose_sporks(self, pose_enabled=True): - self.nodes[0].sporkupdate("SPORK_23_QUORUM_POSE", 0 if pose_enabled else 4070908800) + def set_pose_sporks(self): + if self.options.disable_spork23: + self.nodes[0].sporkupdate("SPORK_23_QUORUM_POSE", 4070908800) + else: + self.nodes[0].sporkupdate("SPORK_23_QUORUM_POSE", 0) self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0) self.wait_for_sporks_same() + def test_no_banning(self, invalidate_proc, expected_connections=None): + [_, instant_ban] = invalidate_proc(self.mninfo[0]) + iters = 2 if instant_ban else 6 + for i in range(iters): + self.log.info(f"Testing no PoSe banning in normal conditions {i + 1}/{iters}") + self.mine_quorum(expected_connections=expected_connections) + def mine_quorum_less_checks(self, expected_members, mninfos_online): # Unlike in mine_quorum we don't know how many complaints and justifications to expect: # the deaf masternode is a regular DKG participant until enough probes to it have failed, @@ -120,7 +132,7 @@ def probes_attempted(): self.wait_until(probes_attempted) - def test_banning(self, invalidate_proc, expected_connections=None, count=2): + def test_banning(self, invalidate_proc, expected_connections=None): mninfos_online = self.mninfo.copy() mninfos_valid = self.mninfo.copy() @@ -129,8 +141,8 @@ def test_banning(self, invalidate_proc, expected_connections=None, count=2): assert not check_banned(self.nodes[0], mn) expected_contributors = len(mninfos_online) - for i in range(count): - self.log.info(f"Testing PoSe banning due to {invalidate_proc.__name__} {i + 1}/{count}") + for i in range(2): + self.log.info(f"Testing PoSe banning due to {invalidate_proc.__name__} {i + 1}/2") mn: MasternodeInfo = mninfos_valid.pop() went_offline, instant_ban = invalidate_proc(mn) expected_complaints = expected_contributors - 1 diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 0a48f447b1c4..80559676cd33 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -98,7 +98,6 @@ EXTENDED_SCRIPTS = [ # These tests are not run by default. # Longest test should go first, to favor running tests in parallel - 'mining_getblocktemplate_longpoll_mempool.py', 'feature_pruning.py', # NOTE: Prune mode is incompatible with -txindex, should work with governance validation disabled though. 'feature_dbcrash.py', 'feature_index_prune.py', @@ -113,9 +112,8 @@ 'feature_fee_estimation.py', 'feature_block.py', # NOTE: needs dash_hash to pass # vv Tests less than 2m vv + 'mining_getblocktemplate_longpoll.py', # FIXME: "socket.error: [Errno 54] Connection reset by peer" on my Mac, same as https://github.com/bitcoin/bitcoin/issues/6651 'feature_maxuploadtarget.py', - 'feature_config_args.py', - 'p2p_dns_seeds.py', 'mempool_updatefromblock.py', 'mempool_persist.py --descriptors', 'p2p_quorum_data.py', @@ -124,7 +122,6 @@ 'p2p_instantsend.py', 'feature_protx_version.py', 'feature_asset_locks.py', # NOTE: needs dash_hash to pass - 'feature_asset_locks_v24.py', # NOTE: needs dash_hash to pass 'feature_llmq_signing.py', # NOTE: needs dash_hash to pass 'feature_llmq_is_retroactive.py', # NOTE: needs dash_hash to pass 'feature_llmq_is_retroactive_session_timeout.py', # NOTE: needs dash_hash to pass @@ -134,6 +131,7 @@ 'feature_masternode_payout_shares.py', 'feature_masternode_shares.py', 'feature_llmq_signing.py --spork21', # NOTE: needs dash_hash to pass + 'feature_llmq_simplepose.py --disable-spork23', # NOTE: needs dash_hash to pass 'feature_llmq_simplepose_capabilities.py --disable-spork23', # NOTE: needs dash_hash to pass 'feature_llmq_rotation.py', # NOTE: needs dash_hash to pass 'feature_llmq_evo.py', # NOTE: needs dash_hash to pass @@ -149,34 +147,13 @@ 'feature_masternode_params_devnet.py', # NOTE: needs dash_hash to pass 'feature_governance.py --descriptors', 'feature_governance_cl.py --descriptors', - 'feature_governance_pruned.py --descriptors', 'feature_governance_trigger_voting.py --descriptors', 'rpc_verifyislock.py', 'feature_dip3_deterministicmns.py --descriptors', # NOTE: needs dash_hash to pass 'feature_notifications.py', # vv Tests less than 60s vv + 'feature_config_args.py', 'mining_basic.py', - 'rpc_blockchain.py --v2transport', - 'rpc_net.py --v1transport', - 'rpc_blockchain.py --v1transport', - 'rpc_net.py --v2transport', - 'p2p_compactblocks_hb.py --v1transport', - 'p2p_compactblocks_hb.py --v2transport', - 'p2p_permissions.py', - 'feature_addressindex.py', - 'rpc_netinfo.py', - 'rpc_getblockfrompeer.py', - 'feature_init.py', - 'p2p_invalid_tx.py --v2transport', - 'wallet_upgradetohd.py --legacy-wallet', - 'wallet_upgradetohd.py --descriptors', - 'feature_minchainwork.py', - 'p2p_addr_relay.py', - 'p2p_v2_misbehaving.py', - 'mempool_accept.py', - 'p2p_node_network_limited.py --v1transport', - 'p2p_node_network_limited.py --v2transport', - 'mining_getblocktemplate_longpoll.py', 'wallet_dust_protection.py --legacy-wallet', 'wallet_dust_protection.py --descriptors', 'rpc_psbt.py --legacy-wallet', @@ -200,6 +177,7 @@ 'wallet_multiwallet.py --legacy-wallet', 'wallet_multiwallet.py --descriptors', 'wallet_multiwallet.py --usecli', + 'p2p_dns_seeds.py', 'wallet_groups.py --legacy-wallet', 'wallet_groups.py --descriptors', 'p2p_blockfilters.py', @@ -288,19 +266,28 @@ 'wallet_transactiontime_rescan.py --descriptors', 'wallet_transactiontime_rescan.py --legacy-wallet', 'p2p_addrv2_relay.py', + 'p2p_compactblocks_hb.py --v1transport', + 'p2p_compactblocks_hb.py --v2transport', 'p2p_disconnect_ban.py --v1transport', 'p2p_disconnect_ban.py --v2transport', 'feature_posix_fs_permissions.py', + 'feature_addressindex.py', 'feature_timestampindex.py', 'feature_spentindex.py', 'rpc_decodescript.py', + 'rpc_blockchain.py --v1transport', + 'rpc_blockchain.py --v2transport', 'rpc_deprecated.py', 'wallet_disable.py', 'wallet_change_address.py --legacy-wallet', 'wallet_change_address.py --descriptors', + 'p2p_addr_relay.py', 'p2p_getaddr_caching.py', 'p2p_getdata.py', 'p2p_addrfetch.py', + 'rpc_net.py --v1transport', + 'rpc_net.py --v2transport', + 'rpc_netinfo.py', 'wallet_keypool.py --legacy-wallet', 'wallet_keypool_hd.py --legacy-wallet', 'wallet_keypool_hd.py --descriptors', @@ -316,8 +303,10 @@ 'p2p_invalid_block.py --v1transport', 'p2p_invalid_block.py --v2transport', 'p2p_invalid_tx.py --v1transport', + 'p2p_invalid_tx.py --v2transport', 'p2p_v2_transport.py', 'p2p_v2_encrypted.py', + 'p2p_v2_misbehaving.py', 'example_test.py', 'wallet_txn_doublespend.py --legacy-wallet', 'wallet_multisig_descriptor_psbt.py --descriptors', @@ -327,6 +316,7 @@ 'wallet_txn_clone.py --mineblock', 'rpc_getblockfilter.py', 'rpc_getmerkleblocks.py', + 'rpc_getblockfrompeer.py', 'rpc_invalidateblock.py', 'feature_txindex.py', 'feature_utxo_set_hash.py', @@ -351,6 +341,7 @@ 'wallet_balance.py --descriptors', 'p2p_initial_headers_sync.py', 'feature_nulldummy.py', + 'mempool_accept.py', 'mempool_expiry.py', 'wallet_import_with_label.py --legacy-wallet', 'wallet_upgradewallet.py --legacy-wallet', @@ -375,6 +366,8 @@ 'feature_bind_port_externalip.py', 'wallet_encryption.py --legacy-wallet', 'wallet_encryption.py --descriptors', + 'wallet_upgradetohd.py --legacy-wallet', + 'wallet_upgradetohd.py --descriptors', 'feature_dersig.py', 'feature_cltv.py', 'feature_new_quorum_type_activation.py', @@ -387,6 +380,7 @@ 'wallet_fallbackfee.py --legacy-wallet', 'wallet_fallbackfee.py --descriptors', 'rpc_dumptxoutset.py', + 'feature_minchainwork.py', 'rpc_estimatefee.py', 'p2p_unrequested_blocks.py', # NOTE: needs dash_hash to pass 'feature_shutdown.py', @@ -405,6 +399,7 @@ 'rpc_external_queue.py', 'rpc_wipewallettxes.py', 'feature_uacomment.py', + 'feature_init.py', 'wallet_coinbase_category.py --legacy-wallet', 'wallet_coinbase_category.py --descriptors', 'feature_filelock.py', @@ -435,6 +430,9 @@ 'feature_coinstatsindex.py', 'wallet_orphanedreward.py', 'wallet_timelock.py', + 'p2p_node_network_limited.py --v1transport', + 'p2p_node_network_limited.py --v2transport', + 'p2p_permissions.py', 'feature_blocksdir.py', 'wallet_startup.py', 'feature_remove_pruned_files_on_startup.py', diff --git a/test/functional/wallet_dust_protection.py b/test/functional/wallet_dust_protection.py index 0fc71e58a2ab..b4a8fadfa497 100755 --- a/test/functional/wallet_dust_protection.py +++ b/test/functional/wallet_dust_protection.py @@ -26,7 +26,6 @@ def add_options(self, parser): def set_test_params(self): self.setup_clean_chain = True self.num_nodes = 4 - self.noban_tx_relay = True # node0: sender (no dust protection) # node1: receiver with dust protection at 10000 duffs # node2: multi-wallet node with dust protection @@ -47,6 +46,7 @@ def run_test(self): self.test_external_dust_locked() self.test_self_send_not_locked() self.test_above_threshold_not_locked() + self.test_disabled_threshold() self.test_existing_utxos_locked_on_restart() self.test_multi_wallet() self.test_invalid_args() @@ -87,21 +87,32 @@ def test_self_send_not_locked(self): self.nodes[0].sendtoaddress(addr_fund, 1) self.generate(self.nodes[0], 1) + # Unlock everything so node1 can spend + locked = node1.listlockunspent() + if locked: + node1.lockunspent(True, locked) + # Self-send a dust amount addr_self = node1.getnewaddress() node1.sendtoaddress(addr_self, 5000 * DUFFS) + self.sync_mempools() # Self-send should not create any new locks locked = node1.listlockunspent() assert_equal(len(locked), 0) - self.generate(node1, 1) + self.generate(self.nodes[0], 1) def test_above_threshold_not_locked(self): """UTXOs above the threshold should NOT be locked.""" self.log.info("Test: above-threshold UTXO is not locked") node1 = self.nodes[1] + # Clear any existing locks + locked = node1.listlockunspent() + if locked: + node1.lockunspent(True, locked) + addr = node1.getnewaddress() # Send 10001 duffs (just above 10000 threshold) self.nodes[0].sendtoaddress(addr, 10001 * DUFFS) @@ -112,6 +123,20 @@ def test_above_threshold_not_locked(self): self.generate(self.nodes[0], 1) + def test_disabled_threshold(self): + """With default threshold (0), nothing should be locked.""" + self.log.info("Test: threshold=0 disables dust protection") + node3 = self.nodes[3] + + addr = node3.getnewaddress() + self.nodes[0].sendtoaddress(addr, 5000 * DUFFS) + self.sync_mempools() + + locked = node3.listlockunspent() + assert_equal(len(locked), 0) + + self.generate(self.nodes[0], 1) + def test_existing_utxos_locked_on_restart(self): """Pre-existing dust UTXOs should be locked when node starts with -dustprotectionthreshold.""" self.log.info("Test: existing UTXOs locked on restart") @@ -185,6 +210,18 @@ def test_multi_wallet(self): locked_a = wallet_a.listlockunspent() assert_equal(len(locked_a), 1) + # Restart and verify locks persist across wallets + self.restart_node(2, ["-dustrelayfee=0", "-dustprotectionthreshold=10000", + "-wallet=wallet_a", "-wallet=wallet_b"]) + self.connect_nodes(0, 2) + wallet_a = node2.get_wallet_rpc('wallet_a') + wallet_b = node2.get_wallet_rpc('wallet_b') + + locked_a = wallet_a.listlockunspent() + locked_b = wallet_b.listlockunspent() + assert_equal(len(locked_a), 1) + assert_equal(len(locked_b), 1) + def test_invalid_args(self): """Invalid -dustprotectionthreshold values should be rejected.""" self.log.info("Test: invalid CLI args rejected") diff --git a/test/functional/wallet_upgradetohd.py b/test/functional/wallet_upgradetohd.py index 2a5a469f0fef..47bfa398cf63 100755 --- a/test/functional/wallet_upgradetohd.py +++ b/test/functional/wallet_upgradetohd.py @@ -36,12 +36,12 @@ def setup_network(self): self.nodes[0].createwallet(self.default_wallet_name, blank=True, load_on_startup=True) self.nodes[0].importprivkey(privkey=self.nodes[0].get_deterministic_priv_key().key, label='coinbase', rescan=True) - def recover_non_hd(self, extra_args=None): + def recover_non_hd(self): self.log.info("Recover non-HD wallet to check different upgrade paths") node = self.nodes[0] self.stop_node(0) shutil.copyfile(os.path.join(node.datadir_path, "non_hd.bak"), os.path.join(node.chain_path, self.default_wallet_name, self.wallet_data_filename)) - self.start_node(0, extra_args) + self.start_node(0) if not self.options.descriptors: assert 'hdchainid' not in node.getwalletinfo() @@ -104,9 +104,10 @@ def run_test(self): # Completely different keys, no HD coins should be recovered assert_equal(balance_non_HD, node.getbalance()) - self.recover_non_hd(['-keypool=10']) + self.recover_non_hd() self.log.info("No mnemonic, no mnemonic passphrase, no wallet passphrase, should result in completely different keys") + self.restart_node(0, extra_args=['-keypool=10']) assert node.upgradetohd("", "", "", True) # Completely different keys, no HD coins should be recovered assert mnemonic != get_mnemonic(node) @@ -158,9 +159,10 @@ def run_test(self): node.rescanblockchain() assert_equal(balance_after, node.getbalance()) - self.recover_non_hd(['-keypool=10']) + self.recover_non_hd() self.log.info("Same mnemonic, no mnemonic passphrase, no wallet passphrase, large enough keepool, should recover all coins with no extra rescan") + self.restart_node(0, extra_args=['-keypool=10']) assert node.upgradetohd(mnemonic[0], mnemonic[1]) assert_equal(mnemonic, get_mnemonic(node)) if not self.options.descriptors: @@ -168,9 +170,10 @@ def run_test(self): # All coins should be recovered assert_equal(balance_after, node.getbalance()) - self.recover_non_hd(['-keypool=10']) + self.recover_non_hd() self.log.info("Same mnemonic, no mnemonic passphrase, no wallet passphrase, large enough keepool, rescan is skipped initially, should recover all coins after rescanblockchain") + self.restart_node(0, extra_args=['-keypool=10']) assert node.upgradetohd(mnemonic[0], mnemonic[1], "", False) assert_equal(mnemonic, get_mnemonic(node)) if not self.options.descriptors: