Skip to content

Conversation

@kwvg
Copy link
Collaborator

@kwvg kwvg commented Jun 18, 2025

Additional Information

Breaking Changes

None expected. New field added in scantxoutset and changes in getblocktemplate behavior on test chains are not breaking.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas (note: N/A)
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation (note: N/A)
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@kwvg kwvg added this to the 23 milestone Jun 18, 2025
@kwvg kwvg added the RPC Some notable changes to RPC params/behaviour/descriptions label Jun 18, 2025
PastaPastaPasta added a commit that referenced this pull request Jun 20, 2025
, bitcoin#25435, bitcoin#23017, bitcoin#25522, bitcoin#26414, partial bitcoin#24587, bitcoin#24637, bitcoin#24623, bitcoin#25445 (implement better tx capabilities in `MiniWallet`)

cfa906e merge bitcoin#26414: Move tx creation to create_self_transfer_multi (Kittywhiskers Van Gogh)
e167162 merge bitcoin#25522: Remove -acceptnonstdtxn=1 from feature_rbf.py (Kittywhiskers Van Gogh)
a5cb9b4 partial bitcoin#25445: Return new_utxo from create_self_transfer in MiniWallet (Kittywhiskers Van Gogh)
b28d90f merge bitcoin#23017: Replace MiniWallet scan_blocks with rescan_utxos (Kittywhiskers Van Gogh)
ebfb239 merge bitcoin#25435: Remove from_node from create_self_transfer* MiniWallet helpers (Kittywhiskers Van Gogh)
144228b merge bitcoin#25356: Remove MiniWallet mempool_valid option (Kittywhiskers Van Gogh)
0622788 merge bitcoin#24941: support skipping mempool checks (feature_fee_estimation.py performance fix) (Kittywhiskers Van Gogh)
9c93e3a merge bitcoin#25228: add BIP-125 rule 5 testcase with default mempool (Kittywhiskers Van Gogh)
b84bcad partial bitcoin#24623: Add diamond-shape prioritisetransaction test (Kittywhiskers Van Gogh)
4621320 partial bitcoin#24637: use MiniWallet for mempool_package_onemore.py (Kittywhiskers Van Gogh)
a21dfd2 partial bitcoin#24587: use MiniWallet for rpc_createmultisig.py (Kittywhiskers Van Gogh)

Pull request description:

  ## Additional Information

  * Dependency for #6726

  * Since [bitcoin#15891](bitcoin#15891) (8ca90f3), we enforce standard transactions on regtest and regrettably, the logic introduced in [bitcoin#24637](bitcoin#24637) (`*self_transfer*()`) had a tendency to create transactions that were non-standard (see below)

    <details>

    <summary>Test failure:</summary>

    ```
    dash@b90780fda2d1:/src/dash$ ./test/functional/mempool_package_onemore.py
    2025-06-18T17:50:19.492000Z TestFramework (INFO): PRNG seed is: 8344907287561424619
    2025-06-18T17:50:19.492000Z TestFramework (INFO): Initializing test directory /tmp/dash_func_test_emt8bu6u
    2025-06-18T17:50:19.765000Z TestFramework (ERROR): JSONRPC error
    Traceback (most recent call last):
      File "/src/dash/test/functional/test_framework/test_framework.py", line 162, in main
        self.run_test()
      File "/src/dash/./test/functional/mempool_package_onemore.py", line 41, in run_test
        utxo, utxo2 = self.chain_tx([utxo], num_outputs=2)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/src/dash/./test/functional/mempool_package_onemore.py", line 28, in chain_tx
        return self.wallet.send_self_transfer_multi(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/src/dash/test/functional/test_framework/wallet.py", line 207, in send_self_transfer_multi
        txid = self.sendrawtransaction(from_node=kwargs['from_node'], tx_hex=tx.serialize().hex())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/src/dash/test/functional/test_framework/wallet.py", line 269, in sendrawtransaction
        txid = from_node.sendrawtransaction(hexstring=tx_hex, maxfeerate=maxfeerate, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/src/dash/test/functional/test_framework/coverage.py", line 49, in __call__
        return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/src/dash/test/functional/test_framework/authproxy.py", line 143, in __call__
        raise JSONRPCException(response['error'], status)
    test_framework.authproxy.JSONRPCException: bad-txns-nonstandard-inputs (-26)
    2025-06-18T17:50:20.266000Z TestFramework (INFO): Stopping nodes
    ```

    </details>

    Two options presented themselves, either temporary relaxing `fRequireStandard` on regtest or backporting all the changes needed to make `*self_transfer*()` create standard transactions and then backporting `MiniWallet` conversions in a separate pull request. The latter approach was taken.

    * The correctness of this pull request can be validated by observing the CI results of [dash#6726](#6726)

  * The backport for [bitcoin#23017](bitcoin#23017) does not include changes to `rpc_blockchain.py` as the relevant `scan_blocks()` call was removed in the partial backport of [bitcoin#23371](bitcoin#23371) (081897c).

  ## Breaking Changes

  None expected. Affects only functional tests.

  ## 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 cfa906e
  UdjinM6:
    utACK cfa906e

Tree-SHA512: 81107b6352cc673cd4d4358da0eba23f971546fae9df0f34bea5b584bfe1a3f820872444314ec65bf181158aeca1cc3880a0b6925101c953db19ecd45d28aa38
kwvg added 7 commits June 20, 2025 18:28
includes:
- 2726b60 (changes excl. wallet.py)

continuation of a21dfd2

checkbalances() has to be modified as the balances are now predominantly
generated by MiniWallet and the nine[1] blocks mined by the test leave
behind immature balances that we must discount.

[1] - 8 blocks mined by 4 calls to do_multisig() and 1 block mined by 1
      call to checkbalances())
includes:
- 95d5d5e

needed for backports affecting mining_prioritisetransaction.py so we
don't need to manually reconnect (or keep around) nodes.
includes:
- 4621320

continuation of b84bcad

need to reestablish connection between nodes to prevent generate calls
from flaking out (connect_nodes())
excludes:
- e502139 (we don't support RBF)
- 60ae116 (see above)
includes changes to feature_fee_estimation.py from bitcoin#25445
(fa04ff6) due to OOO backport needed for correctness
includes changes to feature_dbcrash.py from bitcoin#25445
(fa04ff6) due to OOO backport needed for correctness
@kwvg kwvg marked this pull request as ready for review June 20, 2025 23:08
@kwvg kwvg requested review from PastaPastaPasta, UdjinM6 and knst June 20, 2025 23:08
@coderabbitai
Copy link

coderabbitai bot commented Jun 20, 2025

Walkthrough

The changes span various source and test files, introducing several targeted updates. In the core code, the scantxoutset RPC method now includes a boolean "coinbase" field in its output, and the getblocktemplate RPC handler's peer/IBD checks are bypassed on test chains. In the functional test suite, many tests were refactored to use the MiniWallet utility for transaction creation, UTXO management, and wallet operations, replacing manual raw transaction crafting and direct wallet RPC calls. The MiniWallet itself was enhanced to track coinbase status and confirmations for UTXOs, support mempool-aware rescans, and unify transaction signing logic. Test utility functions were updated to use MiniWallet for large transaction creation. Additionally, the rpc_createmultisig.py test now conditionally executes wallet-dependent code based on wallet availability, and the test runner was updated to remove explicit wallet mode arguments for this script. No exported function or class signatures were altered in the core code, but several test methods and utility functions had their signatures or logic updated to accommodate these changes.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (8)
test/functional/rpc_scantxoutset.py (1)

35-36: Verify the hardcoded coinbase count expectation.

The test asserts that exactly 49 coinbase outputs should be found, but this hardcoded value might be brittle if the test setup changes. Consider adding a comment explaining how this number is derived (e.g., number of blocks generated + any pre-existing coinbase outputs).

+        # Expect 49 coinbase outputs: X blocks from setup + Y from previous operations
         self.log.info("Test if we find coinbase outputs.")
         assert_equal(sum(u["coinbase"] for u in self.nodes[0].scantxoutset("start", [self.wallet.get_descriptor()])["unspents"]), 49)
test/functional/feature_dbcrash.py (1)

189-191: Minor optimization: Use generator expression in sum()

Consider using a generator expression for better memory efficiency as suggested by static analysis.

-            input_amount = int(sum([utxo['value'] for utxo in utxos_to_spend]) * COIN)
+            input_amount = int(sum(utxo['value'] for utxo in utxos_to_spend) * COIN)
test/functional/mining_prioritisetransaction.py (1)

105-133: Consider refactoring to reduce method complexity.

While the MiniWallet integration is correct, the run_test method has grown complex with 20 local variables and 64 statements (pylint warnings). Consider extracting some test logic into helper methods, such as:

  • Initial parameter validation tests (lines 109-124)
  • UTXO setup and transaction batch creation logic
test/functional/test_framework/util.py (1)

617-632: Consider making some parameters keyword-only to improve API clarity.

The function has 6 positional arguments, which exceeds the recommended limit. Consider making less frequently used parameters keyword-only to improve the API:

-def create_lots_of_big_transactions(mini_wallet, node, fee, tx_batch_size, txouts, utxos=None):
+def create_lots_of_big_transactions(mini_wallet, node, fee, tx_batch_size, txouts, *, utxos=None):

This would require callers to explicitly name the utxos parameter when provided, making the code more readable.

test/functional/feature_fee_estimation.py (1)

24-63: Consider refactoring function signature to use keyword arguments.

The function has 7 positional arguments. Consider grouping related parameters or making some keyword-only:

-def small_txpuzzle_randfee(
-    wallet, from_node, conflist, unconflist, amount, min_fee, fee_increment
-):
+def small_txpuzzle_randfee(
+    wallet, from_node, conflist, unconflist, *, amount, min_fee, fee_increment
+):

This would make the fee-related parameters more explicit at call sites.

test/functional/test_framework/wallet.py (3)

94-95: Consider using a dataclass for UTXO representation.

While the current implementation works, consider using a dataclass for better type safety and maintainability:

from dataclasses import dataclass

@dataclass
class UTXO:
    txid: str
    vout: int
    value: Decimal
    height: int
    coinbase: bool
    confirmations: int

This would make the code more maintainable and provide better IDE support.


135-156: Fix code style issues in sign_tx method.

The refactoring correctly handles all wallet modes, but has minor style issues:

-            while not len(der_sig) == 71:
+            while len(der_sig) != 71:
                 der_sig = self._priv_key.sign_ecdsa(sighash)
         else:
-            assert False
+            raise AssertionError(f"Unknown wallet mode: {self._mode}")

201-210: Fix Yoda condition in get_utxos method.

The method implementation is correct, but has a style issue:

-            utxo_filter = filter(lambda utxo: not utxo['coinbase'] or COINBASE_MATURITY <= utxo['confirmations'], self._utxos)
+            utxo_filter = filter(lambda utxo: not utxo['coinbase'] or utxo['confirmations'] >= COINBASE_MATURITY, self._utxos)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce682f2 and 65047fc.

📒 Files selected for processing (17)
  • src/rpc/blockchain.cpp (2 hunks)
  • src/rpc/mining.cpp (1 hunks)
  • test/functional/feature_bip68_sequence.py (16 hunks)
  • test/functional/feature_dbcrash.py (3 hunks)
  • test/functional/feature_fee_estimation.py (10 hunks)
  • test/functional/mempool_compatibility.py (1 hunks)
  • test/functional/mempool_limit.py (2 hunks)
  • test/functional/mempool_package_onemore.py (1 hunks)
  • test/functional/mining_prioritisetransaction.py (4 hunks)
  • test/functional/p2p_eviction.py (5 hunks)
  • test/functional/p2p_permissions.py (2 hunks)
  • test/functional/p2p_tx_download.py (4 hunks)
  • test/functional/rpc_createmultisig.py (4 hunks)
  • test/functional/rpc_scantxoutset.py (1 hunks)
  • test/functional/test_framework/util.py (1 hunks)
  • test/functional/test_framework/wallet.py (6 hunks)
  • test/functional/test_runner.py (1 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
test/functional/feature_dbcrash.py

[refactor] 190-190: Consider using a generator instead 'sum(utxo['value'] for utxo in utxos_to_spend)'

(R1728)

test/functional/mining_prioritisetransaction.py

[refactor] 105-105: Too many local variables (20/15)

(R0914)


[refactor] 105-105: Too many statements (64/50)

(R0915)

test/functional/feature_fee_estimation.py

[refactor] 24-24: Too many arguments (7/5)

(R0913)


[refactor] 24-24: Too many positional arguments (7/5)

(R0917)

test/functional/test_framework/util.py

[refactor] 617-617: Too many arguments (6/5)

(R0913)


[refactor] 617-617: Too many positional arguments (6/5)

(R0917)

test/functional/test_framework/wallet.py

[refactor] 94-94: Too many arguments (7/5)

(R0913)

test/functional/rpc_createmultisig.py

[refactor] 25-25: Too many instance attributes (11/7)

(R0902)


[refactor] 47-47: Too many local variables (18/15)

(R0914)


[refactor] 125-125: Too many local variables (28/15)

(R0914)


[refactor] 125-125: Too many statements (55/50)

(R0915)

🪛 Ruff (0.11.9)
test/functional/test_framework/wallet.py

143-143: Use len(der_sig) != 71 instead of not len(der_sig) == 71

Replace with != operator

(SIM201)


156-156: Do not assert False (python -O removes these calls), raise AssertionError()

Replace assert False

(B011)


204-204: Yoda condition detected

Rewrite as utxo['confirmations'] >= COINBASE_MATURITY

(SIM300)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: linux64-test / Test source
🔇 Additional comments (33)
src/rpc/blockchain.cpp (2)

2425-2425: LGTM: Well-documented new feature

The documentation correctly describes the new "coinbase" field that indicates whether each unspent output is from a coinbase transaction. This enhances the API by providing useful metadata to callers.


2529-2529: LGTM: Clean implementation of coinbase field

The implementation correctly uses coin.IsCoinBase() to determine and expose the coinbase status of each unspent output. This is a backward-compatible enhancement that adds valuable information without affecting existing functionality.

test/functional/test_runner.py (1)

271-271: LGTM! Test consolidation aligns with refactoring objectives.

The consolidation of the two separate rpc_createmultisig.py entries into a single entry without wallet mode flags is consistent with the PR's objective to make the test handle different wallet modes conditionally rather than through separate test runs.

src/rpc/mining.cpp (2)

731-739: LGTM! Proper isolation of test chain behavior.

The conditional bypass of peer connection and IBD checks for test chains is well-implemented. It enables testing of getblocktemplate without requiring complex network setup while maintaining all safety checks for production chains.


742-742: Good placement of the sporkman assertion.

Moving the CHECK_NONFATAL(node.sporkman); outside the conditional ensures it executes regardless of chain type, which is the correct behavior since sporkman is needed for all chains.

test/functional/mempool_compatibility.py (1)

52-52: LGTM! Improved transaction handling with MiniWallet.

The replacement of manual wallet RPC calls with MiniWallet.send_self_transfer() improves test reliability and aligns with the broader test framework modernization. The test logic remains the same while benefiting from standardized UTXO and transaction management.

test/functional/mempool_limit.py (2)

15-15: Good addition of shared utility import.

Importing create_lots_of_big_transactions from the shared test framework utilities promotes code reuse and standardization across mempool-related tests.


64-64: LGTM! Improved code reuse with shared utility function.

Replacing the local send_large_txs method with the shared create_lots_of_big_transactions utility function eliminates code duplication and benefits from the enhanced MiniWallet-based implementation with better fee handling and mempool acceptance checks.

test/functional/p2p_eviction.py (2)

58-59: LGTM: Clean MiniWallet integration

The MiniWallet initialization and UTXO rescanning is correctly implemented, replacing the manual transaction setup.


85-86: LGTM: Simplified transaction creation

The replacement of manual raw transaction construction with self.wallet.create_self_transfer()['tx'] is correct and maintains the same functionality while improving code clarity.

test/functional/p2p_permissions.py (2)

28-30: LGTM: Proper MiniWallet setup

The MiniWallet initialization and UTXO rescanning is correctly implemented at the start of the test.


102-103: LGTM: Correct transaction creation with sequencing

The use of create_self_transfer(sequence=SEQUENCE_FINAL) properly replaces the manual transaction construction while maintaining the required transaction properties for the permission test.

test/functional/p2p_tx_download.py (2)

146-148: LGTM: Proper wallet initialization

The MiniWallet setup at the beginning of run_test is correctly implemented.


82-83: LGTM: Simplified transaction handling

The replacement of manual transaction creation with self.wallet.create_self_transfer() and proper txid extraction from the transaction dictionary is correct and maintains the test functionality.

test/functional/feature_dbcrash.py (3)

205-207: LGTM: Proper MiniWallet integration

The MiniWallet initialization and UTXO rescanning correctly replaces the manual wallet setup, improving test maintainability.


195-200: LGTM: Simplified transaction creation

The use of send_self_transfer_multi with proper parameters effectively replaces the manual transaction construction while maintaining the same test behavior.


264-266: LGTM: Consistent UTXO management

The wallet rescanning and UTXO retrieval properly replaces the manual UTXO list management, maintaining test correctness while improving code clarity.

test/functional/mempool_package_onemore.py (4)

27-31: LGTM: Well-designed helper method

The chain_tx method provides a clean abstraction for transaction chaining using MiniWallet, improving code readability and maintainability.


34-35: LGTM: Proper wallet initialization

The MiniWallet setup correctly replaces the manual transaction and UTXO management infrastructure.


52-59: LGTM: Consistent error handling updates

All error assertions have been properly updated to use the new chain_tx method while maintaining the same test validation logic for mempool ancestor and descendant limits.


39-46: LGTM: Simplified transaction chain construction

The refactored chain building logic using chain_tx and wallet.get_utxo() is much cleaner than the previous manual approach while maintaining identical test behavior.

test/functional/mining_prioritisetransaction.py (3)

7-20: LGTM! Imports are well-organized and necessary.

The added imports support the refactoring to use MiniWallet and are properly organized by module.


32-104: Well-designed test for diamond-shaped transaction prioritization.

The test comprehensively covers prioritization behavior for a diamond-shaped dependency graph, properly testing both in-mempool and post-restart scenarios. Good use of Decimal for precise fee calculations.


144-150: Clean refactoring of transaction creation.

The transaction creation is now much simpler and more maintainable using MiniWallet methods. The fee handling is consistent and the code is more readable.

Also applies to: 209-211

test/functional/feature_bip68_sequence.py (3)

27-27: Correct MiniWallet integration.

The MiniWallet is properly initialized and used throughout the test, simplifying UTXO management and transaction creation.

Also applies to: 53-56, 83-84


95-96: Transaction handling properly migrated to MiniWallet.

The signing and sending of transactions now use MiniWallet methods while preserving the original test logic and error handling.

Also applies to: 108-108, 114-114


397-401: Proper wallet isolation for multi-node test.

Creating a separate MiniWallet instance for node 1 is the correct approach to maintain wallet isolation between nodes.

test/functional/test_framework/util.py (1)

635-641: Clean integration with refactored transaction creation.

The function properly delegates to the refactored create_lots_of_big_transactions with appropriate fee calculation.

test/functional/feature_fee_estimation.py (2)

121-124: Clean test setup with MiniWallet.

The removal of -acceptnonstdtxn=1 is appropriate since MiniWallet creates standard transactions. The initial UTXO splitting is much cleaner using send_self_transfer_multi.

Also applies to: 174-177, 223-224


150-158: Correct integration with refactored transaction creation.

The method properly passes the MiniWallet instance to the refactored small_txpuzzle_randfee function.

test/functional/test_framework/wallet.py (1)

100-118: Excellent enhancement to support mempool-aware UTXO rescanning.

The implementation correctly:

  • Calculates confirmations as height - utxo_height + 1
  • Sorts mempool transactions by ancestor count to match mining behavior
  • Maintains backward compatibility with the optional parameter
test/functional/rpc_createmultisig.py (2)

20-23: Well-implemented MiniWallet integration

The refactoring to use MiniWallet for wallet-independent operations is clean and follows the established patterns from other test files in this PR.

Also applies to: 49-49, 55-55, 161-162


30-31: Proper isolation of wallet-dependent functionality

The conditional logic using is_bdb_compiled() effectively isolates wallet-dependent operations, allowing the test to run in environments without BDB wallet support while maintaining full functionality when available.

Also applies to: 42-45, 51-52, 62-63, 75-84, 128-159

@kwvg
Copy link
Collaborator Author

kwvg commented Jun 21, 2025

Marking as draft due to persistent failure in linux64_build (build, build, build).

@kwvg kwvg marked this pull request as draft June 21, 2025 02:03
kwvg added 6 commits June 21, 2025 21:49
includes changes to util.py, mining_prioritisetransaction.py from
bitcoin#25435 (fa8421b) and changes to util.py from bitcoin#25356
(fa779de) due to OOO backport needed for correctness
getmempoolinfo["loaded"] was introduced in bitcoin#15323 (dash#4609),
shipped as part of v18.x but this version is also needed by
bitcoin#26640 as v0.15 does not recognize "maxfeerate", which MiniWallet
needs.

We also need to delete the datadir of the v18.2.2 node to avoid problems
that could arise from the EvoDb, the files needed for the test are
managed by the test.
…MiniWallet

Running `rescan_utxos()` is necessary to ensure that funds are visible
during the tests.
@kwvg kwvg changed the title backport: merge bitcoin#24587, #24637, #24623, #23075, #24817, #25087, #24839, #26640, #26892, #26280, #26657, #26923, partial bitcoin#19937 (test backports: part 3) backport: merge bitcoin#24587, #24637, #24623, #23075, #24817, #25087, #24839, #20456, #26640, #26892, #26280, #26657, #26923, partial bitcoin#19937 (test backports: part 3) Jun 21, 2025
@kwvg kwvg marked this pull request as ready for review June 21, 2025 23:55
@kwvg kwvg requested review from PastaPastaPasta, UdjinM6 and knst June 21, 2025 23:55
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
test/functional/test_framework/wallet.py (2)

135-156: Address static analysis suggestion and improve code clarity.

The sign_tx method refactoring properly handles all MiniWallet modes explicitly. However, there are a couple of minor improvements suggested by static analysis:

-            while not len(der_sig) == 71:
+            while len(der_sig) != 71:
-        else:
-            assert False
+        else:
+            raise AssertionError("Unknown MiniWallet mode")

The explicit mode handling is much better than the previous implementation and ensures all cases are covered.


201-210: Address static analysis suggestion in coinbase maturity check.

The get_utxos method is well-designed for bulk UTXO retrieval with proper filtering and optional spending. However, there's a minor style improvement:

-        if not include_immature_coinbase:
-            utxo_filter = filter(lambda utxo: not utxo['coinbase'] or COINBASE_MATURITY <= utxo['confirmations'], self._utxos)
+        if not include_immature_coinbase:
+            utxo_filter = filter(lambda utxo: not utxo['coinbase'] or utxo['confirmations'] >= COINBASE_MATURITY, self._utxos)

This addresses the "Yoda condition" flagged by static analysis for better readability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65047fc and 54740ae.

📒 Files selected for processing (11)
  • src/rpc/blockchain.cpp (2 hunks)
  • test/functional/feature_bip68_sequence.py (16 hunks)
  • test/functional/mempool_compatibility.py (3 hunks)
  • test/functional/mempool_limit.py (2 hunks)
  • test/functional/mining_prioritisetransaction.py (4 hunks)
  • test/functional/p2p_eviction.py (5 hunks)
  • test/functional/p2p_permissions.py (2 hunks)
  • test/functional/p2p_tx_download.py (4 hunks)
  • test/functional/rpc_scantxoutset.py (1 hunks)
  • test/functional/test_framework/util.py (1 hunks)
  • test/functional/test_framework/wallet.py (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • test/functional/rpc_scantxoutset.py
  • test/functional/p2p_eviction.py
  • src/rpc/blockchain.cpp
  • test/functional/p2p_permissions.py
  • test/functional/mempool_limit.py
  • test/functional/mempool_compatibility.py
  • test/functional/p2p_tx_download.py
  • test/functional/feature_bip68_sequence.py
🧰 Additional context used
🪛 Pylint (3.3.7)
test/functional/mining_prioritisetransaction.py

[refactor] 105-105: Too many local variables (20/15)

(R0914)


[refactor] 105-105: Too many statements (64/50)

(R0915)

test/functional/test_framework/util.py

[refactor] 617-617: Too many arguments (6/5)

(R0913)


[refactor] 617-617: Too many positional arguments (6/5)

(R0917)

test/functional/test_framework/wallet.py

[refactor] 94-94: Too many arguments (7/5)

(R0913)

🪛 Ruff (0.11.9)
test/functional/test_framework/wallet.py

143-143: Use len(der_sig) != 71 instead of not len(der_sig) == 71

Replace with != operator

(SIM201)


156-156: Do not assert False (python -O removes these calls), raise AssertionError()

Replace assert False

(B011)


204-204: Yoda condition detected

Rewrite as utxo['confirmations'] >= COINBASE_MATURITY

(SIM300)

🔇 Additional comments (15)
test/functional/mining_prioritisetransaction.py (7)

7-21: LGTM: Import changes support MiniWallet refactoring.

The import additions for Decimal, COIN, MAX_BLOCK_SIZE, create_lots_of_big_transactions, gen_return_txouts, and MiniWallet are appropriate for the test modernization.


32-104: LGTM: Well-structured diamond transaction dependency test.

The test_diamond method correctly implements a diamond-shaped transaction dependency graph test:

  • Creates transactions in proper dependency order (tx_a → tx_b/tx_c → tx_d)
  • Tests prioritization both with transactions in mempool and after restart
  • Properly verifies fee delta effects on ancestor/descendant relationships
  • Uses appropriate cleanup with mempool clearing and node restart

The logic for testing prioritization behavior across node restarts with -nopersistmempool is particularly valuable for ensuring consistent behavior.


105-108: LGTM: Proper MiniWallet initialization and UTXO rescan.

The initialization of MiniWallet and calling rescan_utxos() follows the expected pattern for test setup when using the MiniWallet utility.


125-125: LGTM: Diamond test integration.

Appropriate placement of the diamond test call within the test flow.


131-134: LGTM: MiniWallet UTXO creation and block generation.

The pattern of using send_self_transfer_multi followed by generate correctly creates confirmed UTXOs for the test while maintaining proper test isolation.


144-151: LGTM: Updated utility function call with MiniWallet.

The call to create_lots_of_big_transactions correctly passes the MiniWallet instance as the first parameter, matching the updated function signature in util.py.


209-212: LGTM: MiniWallet transaction creation for fee testing.

Using create_self_transfer with fee_rate=0 appropriately creates a zero-fee transaction for testing prioritization of free transactions.

test/functional/test_framework/util.py (2)

617-632: LGTM: Well-refactored function using MiniWallet.

The refactored create_lots_of_big_transactions function properly:

  • Accepts mini_wallet as the first parameter for consistency with MiniWallet patterns
  • Uses mini_wallet.create_self_transfer instead of manual transaction construction
  • Correctly handles fee conversion from float to satoshis
  • Maintains the transaction size by extending with txouts
  • Validates fees through testmempoolaccept before broadcasting
  • Handles optional UTXO parameter with fallback to internal wallet UTXOs

The static analysis warning about too many arguments is acceptable for this utility function given its comprehensive parameter set.


639-641: LGTM: Simplified mine_large_block using refactored utility.

The mine_large_block function correctly delegates to create_lots_of_big_transactions with the updated signature, simplifying the implementation while maintaining the same functionality.

test/functional/test_framework/wallet.py (6)

48-48: LGTM: Added import for coinbase maturity constant.

The import of COINBASE_MATURITY from blocktools is necessary for the new coinbase UTXO filtering logic.


94-95: LGTM: Enhanced UTXO metadata tracking.

The _create_utxo method now correctly tracks coinbase and confirmations fields, which are essential for proper UTXO management and coinbase maturity handling.


100-118: LGTM: Enhanced rescan with mempool support.

The rescan_utxos method improvements are well-implemented:

  • Optional include_mempool parameter with sensible default
  • Proper sorting of mempool transactions by ancestor count (matching Bitcoin Core's block assembly logic)
  • Correct calculation of confirmations based on block height
  • Integration of coinbase field from scan results

The mempool handling logic correctly processes transactions in dependency order.


133-133: LGTM: Consistent UTXO creation in scan_tx.

Creating UTXOs with coinbase=False and confirmations=0 for mempool transactions is correct since these are not coinbase transactions and are unconfirmed.


273-273: LGTM: Simplified transaction signing.

Replacing manual mode-specific scriptSig handling with a call to the unified sign_tx method improves code maintainability and consistency.


282-284: LGTM: Consistent metadata in created UTXOs.

Adding coinbase=False and confirmations=0 to newly created UTXOs is correct since these are manually created transactions that are unconfirmed.

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 54740ae

Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 54740ae

@PastaPastaPasta PastaPastaPasta merged commit a4fcaaa into dashpay:develop Jun 29, 2025
58 of 59 checks passed
This was referenced Jul 25, 2025
PastaPastaPasta added a commit that referenced this pull request Aug 20, 2025
, bitcoin#25616, bitcoin#26005, bitcoin#24855, bitcoin#18554, bitcoin#17204, bitcoin#20562, bitcoin#21166, bitcoin#25044, bitcoin#25364, bitcoin#25525, bitcoin#25512, bitcoin#24678, bitcoin#26747, partial bitcoin#22154, bitcoin#24584 (wallet backports: part 8)

c0f9225 merge bitcoin#26747: fix confusing error / GUI crash on cross-chain legacy wallet restore (Kittywhiskers Van Gogh)
d63ca8a merge bitcoin#24678: Prevent wallet unload on GetWalletForJSONRPCRequest (Kittywhiskers Van Gogh)
2a880d8 merge bitcoin#25512: remove wallet dependency and refactor rpc_signrawtransaction.py (Kittywhiskers Van Gogh)
f405790 merge bitcoin#25525: remove wallet dependency from mempool_updatefromblock.py (Kittywhiskers Van Gogh)
c24c9ea merge bitcoin#25364: remove wallet dependency from feature_nulldummy.py (Kittywhiskers Van Gogh)
a118fe1 test: reduce `num_nodes` in `feature_nulldummy.py` to 1 (Kittywhiskers Van Gogh)
c6eabc1 merge bitcoin#25044: Use MiniWallet in rpc_rawtransaction.py (Kittywhiskers Van Gogh)
4e0725e merge bitcoin#21166: Introduce DeferredSignatureChecker and have SignatureExtractorClass subclass it (Kittywhiskers Van Gogh)
f883122 merge bitcoin#20562: Test that a fully signed tx given to signrawtx is unchanged (Kittywhiskers Van Gogh)
c349dad merge bitcoin#17204: Do not turn OP_1NEGATE in scriptSig into 0x0181 in signing code (Kittywhiskers Van Gogh)
c5e8bd6 merge bitcoin#18554: ensure wallet files are not reused across chains (Kittywhiskers Van Gogh)
0fca914 merge bitcoin#24855: Fix `setwalletflag` disabling of flags (Kittywhiskers Van Gogh)
f15a1b9 merge bitcoin#26005: Fix error handling (copy_file failure in RestoreWallet, and in general via interfaces) (Kittywhiskers Van Gogh)
240765e merge bitcoin#25616: Return `util::Result` from WalletLoader methods (Kittywhiskers Van Gogh)
bd897fa merge bitcoin#25656: return util::Result from `GetReservedDestination` methods (Kittywhiskers Van Gogh)
56accfe merge bitcoin#25721: Replace BResult with util::Result (Kittywhiskers Van Gogh)
03939f2 partial bitcoin#24584: avoid mixing different `OutputTypes` during coin selection (Kittywhiskers Van Gogh)
50ca8cf refactor: remove `CKey` overload for `Create{,AndProcess}Block()` (Kittywhiskers Van Gogh)
9e23b11 merge bitcoin#25218: introduce generic 'Result' class and connect it to CreateTransaction and GetNewDestination (Kittywhiskers Van Gogh)
ec764fd partial bitcoin#22154: Add OutputType::BECH32M and related wallet support for fetching bech32m addresses (Kittywhiskers Van Gogh)

Pull request description:

  ## Additional Information

  * The `CKey` overload for `Create{,AndProcess}Block()` was introduced as a convenience function in [dash#2264](#2264). To allow for the easier backport of [bitcoin#24584](bitcoin#24584) (by resolving an ambiguous overload error) and because `GetScriptForRawPubKey` makes the same construction, it was opted to realign with upstream and drop the overload.

  * Even though we don't actively support any address types that utilize Bech32m, [bitcoin#25656](bitcoin#25656) assumes that `GetReservedDestination` modifies a `bilingual_str` for its error case in order to encapsulate it in a `util::Result`. In order to complete that backport, [bitcoin#22154](bitcoin#22154) has been partially backported.

  * `CKeyHolder` has always assumed that `GetReservedDestination` will succeed without validation of this assumption ([source](https://github.com/dashpay/dash/blob/develop/src/coinjoin/util.cpp#L29-L33)). As [bitcoin#25656](bitcoin#25656) forces us to unwrap the returned value, this assumption has been documented with an `assert` ([source](https://github.com/dashpay/dash/blob/bd897fa7097d3d68d19b8a9af14b23f4007645ca/src/coinjoin/util.cpp#L32-L34))

  * When backporting [bitcoin#21166](bitcoin#21166), we don't have the luxury of a `scriptWitness` to include the redemption script, so `rpc_signrawtransaction.py` must import the script in order to spend it. This creates an additional complication as descriptor wallets do not permit wallets to mix descriptors with and without private keys ([source](https://github.com/dashpay/dash/blob/cc9da5d9e28bf9a7b411dc390523ac6d2dd09de6/src/wallet/rpc/backup.cpp#L1758)) and as P2SH descriptors don't involve a private key, those specific subtests need to be skipped for descriptor wallets.

    * `OP_TRUE` has been appended to the script, this mirrors the `OP_TRUE` in the `scriptWitness` ([source](https://github.com/bitcoin/bitcoin/blob/a97a9298cea085858e1a65a5e9b20d7a9e0f7303/test/functional/rpc_signrawtransaction.py#L270))

  * The subtest `test_signing_with_missing_prevtx_info()` introduced in [bitcoin#25044](bitcoin#25044) requires an extra `walletpassphrase` as the preceding tests that unlock the wallet are not called for descriptor wallets, making the call necessary. It is redundant but harmless for legacy wallets.

  * With the backport of [bitcoin#19937](bitcoin#19937) in [dash#6726](#6726) (as ae7e4cb), we can remove a workaround in `feature_nulldummy.py` where we used two nodes to satisfy `getblocktemplate`'s requirement of a connected node as that requirement was lifted on test chains.

  ## Breaking Changes

  None expected.

  ## How Has This Been Tested?

  A full CoinJoin session run on c0f9225

  ![CoinJoin session run on build c0f9225](https://github.com/user-attachments/assets/1dd31814-8d4a-47ab-95e5-5684818f3971)

  ## 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 c0f9225
  UdjinM6:
    utACK c0f9225

Tree-SHA512: 2217281ea75afe3eb6061e1acbd42afb66ff2ab28c15a3ad03bdb528ef4e40ea30bf1adad8d0ba93310a3d561d6c3f2ad95780b0b972af238523c6f2950a39c7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RPC Some notable changes to RPC params/behaviour/descriptions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants