-
Notifications
You must be signed in to change notification settings - Fork 1.2k
backport: merge bitcoin#25228, #24941, #25356, #25435, #23017, #25522, #26414, partial bitcoin#24587, #24637, #24623, #25445 (implement better tx capabilities in MiniWallet)
#6725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
includes: - 2726b60 (only wallet.py)
includes: - eb3c5c4 We cannot include the actual changes to mempool_package_onemore.py as currently create_self_transfer_multi creates nonstandard transactions that Dash rejects, we will need to do a few backports before we can complete this one.
includes: - fa450c1 We cannot include the changes to mining_prioritisetransaction.py for the same reason as earlier, send_self_transfer_multi() generates non-standard transactions, but we carry on.
excludes: - 687adda (we don't support RBF)
…imation.py performance fix)
MiniWallet)MiniWallet)
WalkthroughThe changes primarily update the test framework's MiniWallet class to improve UTXO management, transaction creation, and fee handling. New methods for multi-input/output transactions, balance calculation, and standardized UTXO creation were introduced. The ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (3)
test/functional/test_framework/wallet.py (2)
114-117: Consider usingcontextlib.suppressfor cleaner exception handling.The current implementation is correct, but could be more pythonic.
+from contextlib import suppress from copy import deepcopy from decimal import Decimal from enum import EnumThen apply this change:
- try: - self.get_utxo(txid=spent["txid"], vout=spent["vout"]) - except StopIteration: - pass + with suppress(StopIteration): + self.get_utxo(txid=spent["txid"], vout=spent["vout"])
232-232: Use generator expression for better performance.- inputs_value_total = sum([int(COIN * utxo['value']) for utxo in utxos_to_spend]) + inputs_value_total = sum(int(COIN * utxo['value']) for utxo in utxos_to_spend)test/functional/mempool_spend_coinbase.py (1)
36-36: Consider using a regular function instead of lambda.While functionally correct, using a def statement is more pythonic.
- coinbase_txid = lambda h: self.nodes[0].getblock(self.nodes[0].getblockhash(h))['tx'][0] + def coinbase_txid(h): + return self.nodes[0].getblock(self.nodes[0].getblockhash(h))['tx'][0]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
test/functional/feature_csv_activation.py(1 hunks)test/functional/mempool_limit.py(2 hunks)test/functional/mempool_reorg.py(3 hunks)test/functional/mempool_spend_coinbase.py(1 hunks)test/functional/mempool_unbroadcast.py(1 hunks)test/functional/test_framework/util.py(1 hunks)test/functional/test_framework/wallet.py(6 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: kwvg
PR: dashpay/dash#6543
File: src/wallet/receive.cpp:240-251
Timestamp: 2025-02-06T14:34:30.466Z
Learning: Pull request #6543 is focused on move-only changes and refactoring, specifically backporting from Bitcoin. Behavior changes should be proposed in separate PRs.
🪛 Ruff (0.11.9)
test/functional/mempool_spend_coinbase.py
36-36: Do not assign a lambda expression, use a def
Rewrite coinbase_txid as a def
(E731)
test/functional/test_framework/wallet.py
114-117: Use contextlib.suppress(StopIteration) instead of try-except-pass
Replace with contextlib.suppress(StopIteration)
(SIM105)
251-251: Do not assert False (python -O removes these calls), raise AssertionError()
Replace assert False
(B011)
277-277: Do not assert False (python -O removes these calls), raise AssertionError()
Replace assert False
(B011)
🪛 Pylint (3.3.7)
test/functional/test_framework/wallet.py
[refactor] 212-212: Too many arguments (7/5)
(R0913)
[refactor] 232-232: Consider using a generator instead 'sum(int(COIN * utxo['value']) for utxo in utxos_to_spend)'
(R1728)
[refactor] 266-266: Too many arguments (6/5)
(R0913)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: linux64_multiprocess-test / Test source
🔇 Additional comments (13)
test/functional/test_framework/wallet.py (4)
93-95: Good abstraction for UTXO creation.The helper method ensures consistent UTXO structure throughout the class.
136-136: Critical fix: rehashing after signing.Correctly updates the transaction hash after adding the signature.
139-149: Excellent improvement to UTXO consistency.The automatic
rescan_utxoscall ensures the wallet's UTXO set remains synchronized with the blockchain state after block generation.
181-186: Clean separation of concerns.The refactoring properly separates transaction creation from broadcasting by requiring
from_nodeonly where needed.test/functional/feature_csv_activation.py (1)
123-123: Correct placement of rehash calls.Adding
tx.rehash()after scriptSig modifications is necessary since these changes occur after signing. The removal of rehash calls aftersign_txis appropriate since it's now handled internally.Also applies to: 131-131
test/functional/mempool_unbroadcast.py (1)
43-43: Correct API usage after MiniWallet refactoring.The removal of
from_nodeparameter aligns with the updatedcreate_self_transfersignature.test/functional/mempool_spend_coinbase.py (1)
31-31: Essential UTXO rescan after blockchain modification.Correctly refreshes the wallet's UTXO set after invalidating blocks.
test/functional/test_framework/util.py (1)
645-645: Correct API usage after MiniWallet refactoring.The simplified call without
from_nodeandmempool_validparameters aligns with the updated MiniWallet interface.test/functional/mempool_limit.py (2)
34-34: LGTM: Parameter removal aligns with updated MiniWallet API.The removal of
mempool_valid=Falseis consistent with the MiniWallet API refactoring mentioned in the PR objectives. The transaction creation logic remains intact.
88-88: LGTM: Consistent API update maintains test functionality.The removal of
mempool_valid=Falseparameter aligns with the updated MiniWallet API while preserving the test's logic to verify that transactions with insufficient fees are rejected with the expected error.test/functional/mempool_reorg.py (3)
34-34: LGTM: Improved UTXO scanning approach.Replacing manual block scanning with
wallet.rescan_utxos()is a more reliable and standardized approach for UTXO discovery, leveraging the enhanced capabilities introduced in the MiniWallet class.
56-56: LGTM: API parameter removal is consistent.The removal of
mempool_valid=Falsealigns with the MiniWallet API refactoring while maintaining the timelock transaction creation logic.
71-72: LGTM: Enhanced UTXO reference structure.Using the
["new_utxo"]field from previous transaction results represents an improvement in UTXO management, providing more structured and reliable access to created UTXOs compared to manual transaction ID lookups.
| elif self._mode == MiniWalletMode.RAW_P2PK: | ||
| vsize = Decimal(168) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other) | ||
| else: | ||
| assert False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Replace assert False with explicit exception.
else:
- assert False
+ raise AssertionError("Invalid wallet mode")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| assert False | |
| else: | |
| - assert False | |
| + raise AssertionError("Invalid wallet mode") |
🧰 Tools
🪛 Ruff (0.11.9)
277-277: Do not assert False (python -O removes these calls), raise AssertionError()
Replace assert False
(B011)
🤖 Prompt for AI Agents
In test/functional/test_framework/wallet.py at line 277, replace the generic
`assert False` statement with an explicit exception that clearly indicates the
error or unexpected condition. Use a specific exception type and provide a
descriptive error message to improve code clarity and debugging.
| for i in range(len(utxos_to_spend)): | ||
| tx.vin[i].scriptSig = CScript([CScript([OP_TRUE])]) | ||
| else: | ||
| assert False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Replace assert False with explicit exception.
Using assert False can be removed by Python optimization.
- else:
- assert False
+ else:
+ raise AssertionError("Invalid wallet mode")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| assert False | |
| else: | |
| raise AssertionError("Invalid wallet mode") |
🧰 Tools
🪛 Ruff (0.11.9)
251-251: Do not assert False (python -O removes these calls), raise AssertionError()
Replace assert False
(B011)
🤖 Prompt for AI Agents
In test/functional/test_framework/wallet.py at line 251, replace the use of
`assert False` with raising an explicit exception such as `raise RuntimeError`
or a more specific exception type. This ensures the failure is not bypassed by
Python optimizations that remove assert statements.
PastaPastaPasta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK cfa906e
UdjinM6
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK cfa906e
, bitcoin#23075, bitcoin#24817, bitcoin#25087, bitcoin#24839, bitcoin#20456, bitcoin#26640, bitcoin#26892, bitcoin#26280, bitcoin#26657, bitcoin#26923, partial bitcoin#19937 (test backports: part 3) 54740ae merge bitcoin#26923: simplify p2p_{tx_download,eviction}.py by using MiniWallet (Kittywhiskers Van Gogh) ace58fd merge bitcoin#26657: Run feature_bip68_sequence.py with MiniWallet (Kittywhiskers Van Gogh) 2f7b3b5 merge bitcoin#26280: Return coinbase flag in scantxoutset (Kittywhiskers Van Gogh) 314c28a merge bitcoin#26892: simplify p2p_permissions.py by using MiniWallet (Kittywhiskers Van Gogh) 2c1e298 merge bitcoin#26640: Run mempool_compatibility.py with MiniWallet (Kittywhiskers Van Gogh) 9937fb8 merge bitcoin#20456: Fix intermittent issue in mempool_compatibility (Kittywhiskers Van Gogh) 6add1c4 merge bitcoin#24839: use MiniWallet for mining_prioritisetransaction.py (Kittywhiskers Van Gogh) 69abcec merge bitcoin#25087: use MiniWallet for feature_dbcrash.py (Kittywhiskers Van Gogh) 917f6b6 merge bitcoin#24817: use MiniWallet for feature_fee_estimation.py (Kittywhiskers Van Gogh) 30b1637 merge bitcoin#23075: Fee estimation functional test cleanups (Kittywhiskers Van Gogh) 8d5883c merge bitcoin#24623: Add diamond-shape prioritisetransaction test (Kittywhiskers Van Gogh) ae7e4cb partial bitcoin#19937: signet mining utility (Kittywhiskers Van Gogh) 1770877 merge bitcoin#24637: use MiniWallet for mempool_package_onemore.py (Kittywhiskers Van Gogh) 4865a3c merge bitcoin#24587: use MiniWallet for rpc_createmultisig.py (Kittywhiskers Van Gogh) Pull request description: ## Additional Information * Depends on #6725 * In [bitcoin#24587](bitcoin#24587), `checkbalances()` in `rpc_createmultisig.py` had to be reworked as we have to _exclude_ the 9 blocks generated by the test itself (excluding the original mining of 149 blocks), i.e. 2 blocks generated by `do_multisig()` ([source](https://github.com/dashpay/dash/blob/4865a3c6228ccb5d08865ad78f16854c25143f35/test/functional/rpc_createmultisig.py#L171), [source](https://github.com/dashpay/dash/blob/4865a3c6228ccb5d08865ad78f16854c25143f35/test/functional/rpc_createmultisig.py#L194)) (itself called 4 times, [source](https://github.com/dashpay/dash/blob/4865a3c6228ccb5d08865ad78f16854c25143f35/test/functional/rpc_createmultisig.py#L58-L61)) and 1 block generated by `checkbalances()` ([source](https://github.com/dashpay/dash/blob/4865a3c6228ccb5d08865ad78f16854c25143f35/test/functional/rpc_createmultisig.py#L111)) * [bitcoin#19937](bitcoin#19937) is partially backported to avoid the need for reconnections (or nodes altogether) just to be able to call `getblocktemplate`, as is done in `mining_prioritisetransaction.py`. * Portions of [bitcoin#25445](bitcoin#25445) (fa04ff6) have been included when backporting [bitcoin#24817](bitcoin#24817) and [bitcoin#25087](bitcoin#25087) for correctness. * Portions of [bitcoin#25435](bitcoin#25435) (fa8421b) and [bitcoin#25356](bitcoin#25356) (fa779de) have been included when backporting [bitcoin#24839](bitcoin#24839) for correctness. * In [bitcoin#26923](bitcoin#26923), `rescan_utxos()` has to be manually called (instead of it being called implicitly) as [bitcoin#26886](bitcoin#26886) has not been backported yet and is not included here due to its longer list of dependent PRs. * In [bitcoin#20456](bitcoin#20456), v18 has been used to replace v0.15 as `getmempoolinfo["loaded"]` was implemented in [bitcoin#15323](bitcoin#15323) (71e38b9 in [dash#4609](#4609)), which is included in v18. * Additionally, [bitcoin#26640](bitcoin#26640) needs a more recent version of Dash Core to be tested against as v0.15 does not recognize `maxfeerate` as an argument ([build](https://github.com/dashpay/dash/actions/runs/15785409773/job/44513474715?pr=6726#step:6:861)), which the `MiniWallet` changes introduced by [bitcoin#26640](bitcoin#26640) rely on. * The deletion of the default data directory to avoid problematic migration logic has been documented in the description on [dash#6327](#6327) ## Breaking Changes None expected. New field added in `scantxoutset` and changes in `getblocktemplate` behavior on test chains are not breaking. ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)** - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation **(note: N/A)** - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: PastaPastaPasta: utACK 54740ae UdjinM6: utACK 54740ae Tree-SHA512: a8c15e1a18f31fc8df7e5445e9f075003e961380114c72226c70dbab0d866d43beb372421ee2e6ce823953af793de3a1112a15d962be27fe7500c5c392171512
Additional Information
Dependency for backport: merge bitcoin#24587, #24637, #24623, #23075, #24817, #25087, #24839, #20456, #26640, #26892, #26280, #26657, #26923, partial bitcoin#19937 (test backports: part 3) #6726
Since bitcoin#15891 (8ca90f3), we enforce standard transactions on regtest and regrettably, the logic introduced in bitcoin#24637 (
*self_transfer*()) had a tendency to create transactions that were non-standard (see below)Test failure:
Two options presented themselves, either temporary relaxing
fRequireStandardon regtest or backporting all the changes needed to make*self_transfer*()create standard transactions and then backportingMiniWalletconversions in a separate pull request. The latter approach was taken.The backport for bitcoin#23017 does not include changes to
rpc_blockchain.pyas the relevantscan_blocks()call was removed in the partial backport of bitcoin#23371 (081897c).Breaking Changes
None expected. Affects only functional tests.
Checklist