Skip to content

backport: bitcoin#25383, 25535, 25337#6524

Merged
PastaPastaPasta merged 3 commits intodashpay:developfrom
vijaydasmp:Jan_2025_04
Apr 3, 2025
Merged

backport: bitcoin#25383, 25535, 25337#6524
PastaPastaPasta merged 3 commits intodashpay:developfrom
vijaydasmp:Jan_2025_04

Conversation

@vijaydasmp
Copy link

bitcoin backports

@github-actions
Copy link

github-actions bot commented Feb 6, 2025

This pull request has conflicts, please rebase.

@github-actions
Copy link

This pull request has conflicts, please rebase.

@vijaydasmp vijaydasmp changed the title backport: bitcoin#25383, 25471, 25535, 19393, 25337 backport: bitcoin#25383, 25535, 19393, 25337 Feb 22, 2025
@vijaydasmp vijaydasmp force-pushed the Jan_2025_04 branch 6 times, most recently from 007a285 to f246628 Compare March 1, 2025 15:18
@vijaydasmp vijaydasmp changed the title backport: bitcoin#25383, 25535, 19393, 25337 backport: bitcoin#25383, 25535, 25337 Mar 1, 2025
@vijaydasmp vijaydasmp marked this pull request as ready for review March 2, 2025 01:08
@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2025

Walkthrough

The changes update several aspects of wallet functionality and its testing. In wallet interfaces, the getAddresses method has been modified to include the const qualifier, indicating that it does not modify state. The address book system has been restructured by removing the GetLabelAddresses method and introducing a new filtering structure (AddrBookFilter), along with three new methods: ForEachAddrBookEntry, ListAddrBookAddresses, and ListAddrBookLabels to handle address data more generically. In the Berkeley and wallet database components, initialization and version-handling routines have been streamlined, including the removal of specific version-setting logic. The RPC code has been refactored by eliminating deprecated functions, updating collection types from sets to vectors, and enhancing address processing logic. Additionally, test scripts have been modified to update node configurations (switching from non-standard transaction acceptance to a zero dust relay fee) and include extra verifications for address classifications.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5a70462a8af12a32593b5e5b1227e793f518391 and a7d4127.

📒 Files selected for processing (1)
  • src/interfaces/wallet.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/interfaces/wallet.h

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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: 0

🧹 Nitpick comments (2)
src/wallet/wallet.cpp (2)

2903-2910: Add documentation about concurrency

This method relies on the wallet lock being held but does not explicitly mention it in the function signature or comments. Consider clarifying that the caller must hold cs_wallet to avoid confusion.


2927-2940: Clarify handling of empty “purpose” argument

When the “purpose” parameter is empty, the logic adds all non-change labels to the returned set. Consider documenting this fallback scenario or validating that it matches the intended design for filtering address labels by purpose.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 26ea618 and 2573d091234384e17175eca188c441a6d3a85a53.

📒 Files selected for processing (10)
  • src/interfaces/wallet.h (1 hunks)
  • src/wallet/bdb.cpp (0 hunks)
  • src/wallet/interfaces.cpp (1 hunks)
  • src/wallet/rpcwallet.cpp (6 hunks)
  • src/wallet/wallet.cpp (1 hunks)
  • src/wallet/wallet.h (1 hunks)
  • src/wallet/walletdb.cpp (2 hunks)
  • test/functional/feature_dbcrash.py (2 hunks)
  • test/functional/wallet_basic.py (1 hunks)
  • test/functional/wallet_listreceivedby.py (1 hunks)
💤 Files with no reviewable changes (1)
  • src/wallet/bdb.cpp
🧰 Additional context used
🪛 Cppcheck (2.10-2)
src/wallet/interfaces.cpp

[error] 225-225: Syntax Error

(internalAstError)

🔇 Additional comments (20)
src/interfaces/wallet.h (1)

137-137: Excellent improvement for const-correctness.

Adding the const qualifier to the getAddresses() method properly indicates that it doesn't modify the wallet's state. This follows C++ best practices and enables calling the method on const instances of the Wallet interface.

test/functional/wallet_listreceivedby.py (1)

65-68: Good test enhancement for address classification.

This addition improves test coverage by validating that no addresses returned by listreceivedbyaddress() are change addresses. This helps ensure that the address filtering logic properly distinguishes between receiving addresses and change addresses, which is crucial for accurate wallet display and accounting.

test/functional/wallet_basic.py (1)

30-30: Improved test configuration with more specific parameter.

Replacing -acceptnonstdtxn=1 with -dustrelayfee=0 is a good refinement that:

  1. Uses a more targeted approach to handling small-value outputs
  2. Maintains other transaction standardness rules while specifically addressing dust handling
  3. Provides better alignment with how small outputs are handled in production environments

This change makes the tests more precise without broadly bypassing all standardness checks.

Also applies to: 34-34

src/wallet/walletdb.cpp (2)

883-885: Enhanced wallet version handling.

The addition of the has_last_client variable properly tracks whether the last client version was successfully read from the database. This improves logging clarity by showing both the wallet version and client version in a single message.


907-907: More robust version update logic.

The revised condition !has_last_client || last_client != CLIENT_VERSION ensures the version is properly updated both when it's missing from the database and when it differs from the current client version. This provides better handling for new wallets and migration scenarios.

test/functional/feature_dbcrash.py (3)

65-66: Improved documentation clarity for node configuration

The comment has been updated to better clarify that node3 will handle "dust" outputs, which aligns with the parameter change below.


66-66: Configuration parameter update from -acceptnonstdtxn to -dustrelayfee=0

The change replaces the older non-standard transaction acceptance flag with a more specific dust relay fee setting. This provides a more targeted approach for testing with small value outputs by explicitly setting a zero dust threshold rather than broadly accepting non-standard transactions.


220-224: Improved UTXO creation strategy and verification

The UTXO creation process has been refactored from a single large batch of 5000 UTXOs to 5 smaller batches of 1000 each. This approach:

  1. Keeps the same total number of UTXOs (5000)
  2. Provides more granular control over the creation process
  3. Adds a verification step to ensure the mempool is empty after UTXO generation

This change improves test robustness by breaking the work into smaller chunks and adding explicit verification.

src/wallet/wallet.h (3)

797-802: Added a flexible filtering structure for address book operations

The new AddrBookFilter structure provides a clean way to filter address book entries by label and whether to include change addresses. The default behavior (ignoring change addresses) is sensible as change addresses are typically not relevant for most user-facing operations.


804-813: Added flexible method for retrieving filtered address book data

The ListAddrBookAddresses method enables more flexible retrieval of address data by accepting an optional filter parameter. This is a good improvement over the removed GetLabelAddresses method as it provides more powerful filtering capabilities.


814-819: Added utility methods for address book operations

The new methods ListAddrBookLabels and ForEachAddrBookEntry provide a clean interface for:

  1. Retrieving all labels for a specific purpose
  2. Iterating through address book entries with a callback function

These additions follow good programming practices by:

  • Using a callback pattern for iteration that avoids exposing internal data structures
  • Providing specific functionality for common address book operations
  • Making the code more maintainable and easier to understand
src/wallet/interfaces.cpp (2)

208-219: Updated address lookup to use the new FindAddressBookEntry method

The implementation of getAddress has been simplified by using FindAddressBookEntry instead of manually checking the address book. This change improves code maintainability by:

  1. Reducing duplicate code
  2. Centralizing the logic for finding address book entries
  3. Using a consistent approach for address book access across the codebase

221-230: Added const qualifier and improved address retrieval implementation

Two key improvements in this change:

  1. The getAddresses method is now marked as const, correctly indicating that it doesn't modify the wallet state
  2. The implementation now uses the new ForEachAddrBookEntry callback method instead of direct iteration

This implementation:

  • Is more concise and easier to understand
  • Properly filters out change addresses
  • Uses a consistent pattern for address book access
  • Correctly constructs the result vector in a single operation
🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 225-225: Syntax Error

(internalAstError)

src/wallet/wallet.cpp (1)

2911-2926: Verify behavior for empty labels

The filter logic correctly handles both ignore-change and optional label matching. However, if the label filter is set but the address has an empty label, the function will skip it. Verify if this is intended or if an empty label should be handled differently (e.g., treat empty label as a valid match).

src/wallet/rpcwallet.cpp (6)

543-543: Data structure change from set to vector

This change from std::set<CTxDestination> to std::vector<CTxDestination> alters the fundamental container type for addresses. While vectors offer better cache locality, be aware that checking for address existence now has O(n) complexity instead of O(log n) that sets provide.


548-548: API migration to more flexible address filtering

The code now uses the new ListAddrBookAddresses method with AddrBookFilter instead of the older GetLabelAddresses. This is part of a broader refactoring to provide more versatile address book querying capabilities.


559-559: Switched from set insertion to vector append

Changed from address_set.insert(dest) to address_vector.emplace_back(dest), consistent with the container type change. Note that emplace_back is generally more efficient than push_back for complex objects as it constructs the element in-place.


579-579: Modified address existence check

The address lookup has changed from the efficient address_set.count(address) to the linear search std::find(address_vector.begin(), address_vector.end(), address) != address_vector.end(). This maintains the same functionality but may be less efficient for large address collections.


3949-3966: Refactored label-based address retrieval using ForEachAddrBookEntry

The implementation of getaddressesbylabel has been updated to use a lambda with the new ForEachAddrBookEntry method, replacing a direct loop over address book entries. This approach is more maintainable as it centralizes address book iteration logic and simplifies the calling code.

The lambda function now directly constructs and adds the value object to the results instead of using the removed AddressBookDataToJSON function.


4013-4013: Updated label retrieval to use new API

This line now uses pwallet->ListAddrBookLabels(purpose) rather than directly iterating through the address book entries, which is consistent with the address book API modernization.

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 (5)
src/wallet/interfaces.cpp (1)

217-218: Direct access to entry fields

While GetLabel() is used for the label field, direct access is used for the purpose field. Consider creating a getter method for purpose as well for consistency.

src/wallet/rpcwallet.cpp (4)

543-543: Consider potential performance implications of using a vector instead of a set.
If the size of address_vector grows large, membership checks with std::find operate in O(n) time, which might degrade performance compared to a set-based approach.


579-579: Watch out for repeated linear searches on address_vector.
Using std::find every time could introduce inefficiency if the vector grows large.


1000-1001: Lambda captures everything by reference; confirm no unintended captures.
Capturing [&] is convenient but requires careful maintenance if more external variables are used inside the lambda.


1041-1047: Consider extracting this filtered-address logic into its own function.
The nested if-else logic from lines 1041 to 1047 could be refactored for clarity.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2573d091234384e17175eca188c441a6d3a85a53 and 6398dc8c778b49c5bf6673f72b33c03d1d82f66c.

📒 Files selected for processing (8)
  • src/interfaces/wallet.h (1 hunks)
  • src/wallet/interfaces.cpp (1 hunks)
  • src/wallet/rpcwallet.cpp (9 hunks)
  • src/wallet/wallet.cpp (1 hunks)
  • src/wallet/wallet.h (1 hunks)
  • test/functional/feature_dbcrash.py (2 hunks)
  • test/functional/wallet_basic.py (1 hunks)
  • test/functional/wallet_listreceivedby.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/interfaces/wallet.h
  • test/functional/wallet_basic.py
  • test/functional/wallet_listreceivedby.py
  • test/functional/feature_dbcrash.py
🧰 Additional context used
🪛 Cppcheck (2.10-2)
src/wallet/interfaces.cpp

[error] 225-225: Syntax Error

(internalAstError)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: arm-linux-gnueabihf / Build depends
🔇 Additional comments (14)
src/wallet/interfaces.cpp (3)

208-209: Clean implementation of address lookup

The switch to using FindAddressBookEntry with explicit allow_change=false parameter simplifies the code and makes the intent clearer.


211-212: Usage of accessor method for label

Good use of the GetLabel() accessor method rather than directly accessing the label field.


221-229: Improved implementation using ForEachAddrBookEntry

The refactoring makes good use of the new ForEachAddrBookEntry method to iterate over address book entries. The lambda function properly filters out change addresses and creates the result vector with all necessary information. The method is correctly marked as const to indicate it doesn't modify the wallet state.

The code properly declares exclusive lock requirements in the lambda to ensure proper concurrent access handling.

🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 225-225: Syntax Error

(internalAstError)

src/wallet/wallet.h (3)

797-802: Well-designed filter structure

The AddrBookFilter struct is well-designed with appropriate use of std::optional for the label and sensible defaults. The comments clearly explain the purpose of each field.


804-807: Flexible address book filtering method

The ListAddrBookAddresses method provides a flexible way to filter address book entries with the optional filter parameter. It's correctly marked as const and requires the wallet lock.


809-812: Clear method for retrieving address labels

The ListAddrBookLabels method provides a clean way to retrieve unique labels associated with a specific purpose. Using a std::set for the return type appropriately ensures uniqueness.

src/wallet/wallet.cpp (3)

2903-2909: Well-structured iteration over address book entries.

This helper method cleanly encapsulates the iteration logic, allowing the caller to easily process each address book entry. The read-only usage (function is const) is safe, and there are no obvious correctness or performance issues.


2911-2923: Parameter-driven address filtering is effective.

The use of an optional filter object and a lambda to exclude change addresses or addresses not matching a specified label is straightforward and efficient. The AssertLockHeld(cs_wallet) precondition ensures thread safety for reading the address book. No issues are evident.


2927-2939: Appropriate label retrieval functionality.

This method correctly gathers distinct labels, ignoring change entries if specified, and matches a requested purpose if provided. Lock acquisition (AssertLockHeld(cs_wallet)) is properly enforced. Implementation appears correct with no security or performance concerns.

src/wallet/rpcwallet.cpp (5)

548-548: Verify correctness of the new ListAddrBookAddresses usage.
Ensure all call sites that previously expected addresses from GetLabelAddresses correctly handle the list returned by ListAddrBookAddresses.


559-559: Emplacing single destination into the vector looks correct.
No immediate issues spotted; consistent with the shift to a vector container.


954-954: Usage of std::optional<CTxDestination> is clear and self-explanatory.
This approach provides a robust way to handle the presence or absence of a filtered address.


1004-1004: Early return looks correct.
Prevents unnecessary processing when there is no matching tally entry and fIncludeEmpty is false.


1050-1051: Logic for label-based tally is straightforward.
This block nicely handles the aggregation of amounts by label.

Comment on lines 814 to 817
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Potential inconsistency in ForEachAddrBookEntry documentation

The documentation comment states that iteration "Stops when the provided 'ListAddrBookFunc' returns false", but the function type is defined with a void return type, which can't return a boolean value to control iteration.

Verify that either:

  1. The callback function should return a boolean (in which case the function type should be changed), or
  2. The documentation should be updated to match the actual behavior

🏁 Script executed:

#!/bin/bash
# Check the implementation of ForEachAddrBookEntry to see if it expects a boolean return
grep -A 15 "void CWallet::ForEachAddrBookEntry" src/wallet/wallet.cpp

Length of output: 840


Update documentation for ForEachAddrBookEntry to correctly reflect its behavior

There is an inconsistency: the documentation claims that iteration stops when the callback returns false, yet the callback type is defined as void and the implementation iterates over all entries without checking any return value. Please update the comment to indicate that the address book is fully iterated without an early termination condition.

  • Location: src/wallet/wallet.h (Lines 814–819)
  • Action: Revise the documentation comment to remove any reference to stopping on a false return value.

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

♻️ Duplicate comments (1)
src/wallet/wallet.h (1)

814-819: ⚠️ Potential issue

Update documentation for ForEachAddrBookEntry

There is an inconsistency in the documentation comment. It states that iteration "Stops when the provided 'ListAddrBookFunc' returns false", but the function type is defined with a void return type, which can't return a boolean to control iteration.

Please update the documentation to accurately reflect the behavior of the function. Either:

  1. Change the comment to indicate that all entries are always processed, or
  2. Modify the ListAddrBookFunc type to return a boolean if early termination is desired
🧹 Nitpick comments (3)
src/wallet/wallet.cpp (1)

2903-2909: Consider asserting the wallet lock for consistency.
The function iterates over m_address_book, yet it does not explicitly assert cs_wallet is held. Other similar methods (ListAddrBookAddresses, ListAddrBookLabels) do so. To maintain consistency and clarity about concurrency requirements, consider adding the lock assertion here as well.

Here is a possible change:

 void CWallet::ForEachAddrBookEntry(const ListAddrBookFunc& func) const
+{
+    AssertLockHeld(cs_wallet);
     for (const auto& item : m_address_book) {
         ...
     }
 }
src/wallet/rpcwallet.cpp (2)

543-559: Consider potential performance trade-offs when using a vector instead of a set.

These lines replace the previous set-based structure with a vector (address_vector) for storing addresses. While vectors can be more cache-friendly and typically faster for small collections, lookups via std::find are O(n), which may be a concern for larger address lists. If lookups are expected to happen frequently on a large collection, consider using a suitable set-like container or caching lookups to maintain efficiency.


1000-1008: Consider renaming the lambda for clarity.

The introduced lambda function named func is correct, but giving it a more descriptive name (e.g., processAddressBookEntry) would improve readability.

-    const auto& func = [&](const CTxDestination& address, const std::string& label, const std::string& purpose, bool is_change) {
+    const auto& processAddressBookEntry = [&](const CTxDestination& address, const std::string& label, const std::string& purpose, bool is_change) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6398dc8c778b49c5bf6673f72b33c03d1d82f66c and bfd640ca97faa79abff93dc053a4f5bf3c792594.

📒 Files selected for processing (6)
  • src/interfaces/wallet.h (1 hunks)
  • src/wallet/interfaces.cpp (1 hunks)
  • src/wallet/rpcwallet.cpp (9 hunks)
  • src/wallet/wallet.cpp (1 hunks)
  • src/wallet/wallet.h (1 hunks)
  • test/functional/wallet_listreceivedby.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/interfaces/wallet.h
  • test/functional/wallet_listreceivedby.py
🧰 Additional context used
🪛 Cppcheck (2.10-2)
src/wallet/interfaces.cpp

[error] 225-225: Syntax Error

(internalAstError)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: arm-linux-gnueabihf / Build depends
  • GitHub Check: x86_64-pc-linux-gnu / Build depends
  • GitHub Check: x86_64-w64-mingw32 / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
🔇 Additional comments (14)
src/wallet/interfaces.cpp (3)

208-210: Improved address lookup with FindAddressBookEntry

The change from direct map access to the FindAddressBookEntry method provides better encapsulation and explicit handling of change addresses. This approach is more robust and maintainable.


211-218: Updated accessor pattern for address book entries

The switch from it->second.name to entry->GetLabel() aligns with the new address book structure. The method now properly handles the updated data structure while maintaining the same behavior.


221-228: Enhanced implementation with const qualifier and callback pattern

The addition of the const qualifier correctly indicates this method doesn't modify wallet state. The implementation is improved by replacing direct iteration with the ForEachAddrBookEntry callback pattern, which provides better encapsulation and cleaner code.

Note: The cppcheck error on line 225 appears to be a false positive related to the EXCLUSIVE_LOCKS_REQUIRED thread safety annotation.

🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 225-225: Syntax Error

(internalAstError)

src/wallet/wallet.cpp (2)

2911-2925: Implementation looks correct.
This function properly locks the wallet (AssertLockHeld(cs_wallet)) and uses ForEachAddrBookEntry with a concise lambda to filter addresses by change status and optional label. The design is straightforward and appears robust.


2927-2939: Straightforward label filtering.
The method is clear, ignoring change addresses and collecting labels that match the specified purpose. This approach is consistent with the rest of the address-book-related methods.

src/wallet/wallet.h (3)

796-802: Clean and well-structured AddrBookFilter struct

Good addition of a filtering structure with sensible defaults. The optional label filter and the change address exclusion flag provide flexible querying capabilities for address book entries.


804-808: Good API design for ListAddrBookAddresses

This method introduces a more flexible way of retrieving address book entries with filtering capabilities. This is a good enhancement over the removed GetLabelAddresses method, allowing for more powerful queries.


809-813: Nicely implemented ListAddrBookLabels method

This method is well-designed to retrieve a set of unique labels for a given purpose. Using a std::set is the appropriate data structure for maintaining uniqueness of labels.

src/wallet/rpcwallet.cpp (6)

954-959: LGTM: Address filtering logic is well-structured.

The conditional checks (!by_label && params.size() > 4) and the subsequent decoding of params[4] ensure safe usage. The new filtering approach for a single filtered_address is straightforward and correct, and invalid addresses are robustly handled. No further changes required.


974-985: Clear conditional checks for filtered addresses and ownership.

This loop properly extracts the destination, checks it against the optional filtered_address, and verifies wallet ownership via (mine & filter). The flow guards against invalid or irrelevant outputs and should behave correctly in both the filtered and unfiltered scenarios.


1013-1013: Logic for tallying known addresses is clear.

The early check on it != mapTally.end() prevents erroneous lookups, and the subsequent else branch handles addresses not already added to the tally. The flow remains consistent, with no obvious logical or correctness issues.

Also applies to: 1024-1024


1032-1034: Good addition of transaction IDs to the response.

Collecting and pushing back the txids into the JSON array provides clear traceability of transactions associated with each address. Implementation looks correct and should not introduce performance concerns.


1040-1040: No issues with lambda closure.

This is simply the end brace for the lambda, and the closure is syntactically correct.


1042-1052: Well-handled branching for optional address filtering.

By either processing a single filtered_address or iterating over the entire address book, the code comprehensively covers both scenarios. The subsequent logic referencing label_tally and by_label is straightforward and consistent with the rest of the function.

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 (4)
src/wallet/rpcwallet.cpp (4)

543-559: Check for potential duplicates when using a vector instead of a set.

Switching from a set to a vector means insertions no longer enforce uniqueness. If duplicates are undesirable here, consider preserving the set-based structure or add extra checks to prevent duplicates.


580-580: Consider performance implications of linear membership checks.

Using std::find on a std::vector is O(n). If the vector can grow large, you may consider a std::unordered_set or std::set to reduce lookup costs.


979-979: Suggest clarifying the comparison with optional.

Rather than if (filtered_address && !(filtered_address == address)), explicitly compare filtered_address.value() != address for readability:

- if (filtered_address && !(filtered_address == address)) {
+ if (filtered_address && filtered_address.value() != address) {

985-985: Improve clarity of conditional check.

if (!(mine & filter)) could be made clearer by using an equality check:

- if (!(mine & filter))
+ if ((mine & filter) == 0)

This emphasizes that no bits are set in common.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7beb411a2a206907d2b1fc7dbb70063a24b1c3ef and bb26584fb836ed10239e56644fbbd7ecd428224c.

📒 Files selected for processing (8)
  • src/interfaces/wallet.h (1 hunks)
  • src/wallet/interfaces.cpp (1 hunks)
  • src/wallet/rpcwallet.cpp (9 hunks)
  • src/wallet/wallet.cpp (1 hunks)
  • src/wallet/wallet.h (1 hunks)
  • test/functional/feature_dbcrash.py (2 hunks)
  • test/functional/wallet_basic.py (1 hunks)
  • test/functional/wallet_listreceivedby.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/interfaces/wallet.h
  • test/functional/wallet_basic.py
  • test/functional/wallet_listreceivedby.py
  • test/functional/feature_dbcrash.py
🧰 Additional context used
🪛 Cppcheck (2.10-2)
src/wallet/interfaces.cpp

[error] 225-225: Syntax Error

(internalAstError)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: x86_64-w64-mingw32 / Build depends
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: x86_64-pc-linux-gnu / Build depends
  • GitHub Check: arm-linux-gnueabihf / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
🔇 Additional comments (19)
src/wallet/interfaces.cpp (3)

208-209: Improved error handling with early return pattern

The new implementation uses the FindAddressBookEntry method and an early return pattern for better error handling when an address is not found. This is a more straightforward approach than the previous iterator-based solution.


211-217: More direct access to entry properties

The code now directly accesses properties from the address book entry object rather than potentially using iterator dereferencing, making the code more readable and less error-prone.


221-228: Cleaner implementation with higher-order function

The getAddresses method has been updated to use the ForEachAddrBookEntry higher-order function, which:

  1. Makes the code more maintainable by abstracting the iteration logic
  2. Properly handles filtering of change addresses
  3. Uses a cleaner callback approach for populating the result vector

The addition of the const qualifier to the method signature correctly reflects that this method doesn't modify the wallet state, which improves API clarity and enables compiler optimizations.

🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 225-225: Syntax Error

(internalAstError)

src/wallet/wallet.cpp (3)

2903-2909: Well-designed iterator with a clear lambda interface

This new method provides a clean abstraction for iterating through address book entries, passing each entry's components to a provided function. Using a function argument allows for flexible processing of address book entries without duplicating iteration logic.


2911-2925: Good implementation of address filtering with optional filter parameter

The ListAddrBookAddresses method efficiently leverages the iterator pattern established by ForEachAddrBookEntry. The implementation correctly handles the optional filter parameter with a sensible default, and properly enforces thread safety through the AssertLockHeld. The filtering logic is clear and concise.


2927-2939: Clean implementation for collecting unique labels

This method properly uses a set for deduplication of labels, and correctly applies filtering based on the provided purpose parameter. The implementation avoids including change addresses in the results, which is appropriate for most UI and RPC use cases.

src/wallet/wallet.h (4)

796-802: Well-designed filtering structure added

Good introduction of the AddrBookFilter struct which provides a clean way to filter address book entries by label and to control whether change addresses are included. Using std::optional for the label filter is appropriate since filtering by label is optional.


804-807: Approve new address book listing method

The ListAddrBookAddresses method provides a flexible way to retrieve filtered address book entries, replacing the removed GetLabelAddresses method. Taking an optional filter parameter is a good design choice.


809-812: Approve labels listing method

The method correctly retrieves all known labels for a specific purpose from the address book. This is a useful addition for wallet interfaces that need to display label lists.


814-819: Update documentation for ForEachAddrBookEntry to correctly reflect its behavior

There is an inconsistency: the documentation claims that iteration stops when the callback returns false, yet the callback type is defined as void and the implementation iterates over all entries without checking any return value. Please update the comment to remove any reference to stopping on a false return value.

src/wallet/rpcwallet.cpp (9)

954-954: Looks good.

Introducing std::optional<CTxDestination> clarifies intent and is a safe way to represent optional addresses. No concerns here.


1001-1001: Early return for change addresses.

This logic is straightforward: skipping further processing for addresses flagged as change. No issues found.


1004-1004: Guard clause is valid.

This return statement logically avoids processing non-tallied addresses when !fIncludeEmpty.


1013-1013: Conditional check is straightforward.

No functional concerns; the code is clear.


1032-1033: Loop usage is concise.

Appending each txid’s hex to the list is correct. Looks good.


1042-1043: Optional usage is clean.

Using if (filtered_address) followed by dereferencing is safe and clear.


1045-1045: Lambda invocation approach is valid.

No issues found in calling the provided function pointer.


1047-1048: Fallback logic is clear.

Invoking ForEachAddrBookEntry when no specific filter is set is appropriately placed.


1050-1051: Label-based tally loop is straightforward.

The logic for aggregating amounts by label is coherent and correct.

UdjinM6
UdjinM6 previously approved these changes Mar 10, 2025
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 bb26584fb836ed10239e56644fbbd7ecd428224c

@vijaydasmp
Copy link
Author

Hello @PastaPastaPasta , requesting review /approve

@vijaydasmp
Copy link
Author

Hello @PastaPastaPasta requesting review

@github-actions
Copy link

This pull request has conflicts, please rebase.

@github-actions
Copy link

This pull request has conflicts, please rebase.

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

♻️ Duplicate comments (1)
src/wallet/wallet.h (1)

814-819: ⚠️ Potential issue

Documentation inconsistency in ForEachAddrBookEntry

The documentation comment states that iteration "Stops when the provided 'ListAddrBookFunc' returns false", but the function type is defined with a void return type, which can't return a boolean value to control iteration.

Update the documentation to match the actual behavior, which appears to be iterating through all address book entries without an early termination condition.

- * Stops when the provided 'ListAddrBookFunc' returns false.
+ * Iterates through all address book entries and calls the provided function for each entry.
🧹 Nitpick comments (1)
src/wallet/rpcwallet.cpp (1)

579-580: Potential performance concern with membership check
This line uses std::find on the vector, which has O(n) complexity. For large address sets, consider using a set for faster lookups.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bb26584fb836ed10239e56644fbbd7ecd428224c and c5a70462a8af12a32593b5e5b1227e793f518391.

📒 Files selected for processing (10)
  • src/interfaces/wallet.h (1 hunks)
  • src/wallet/bdb.cpp (0 hunks)
  • src/wallet/interfaces.cpp (1 hunks)
  • src/wallet/rpcwallet.cpp (9 hunks)
  • src/wallet/wallet.cpp (1 hunks)
  • src/wallet/wallet.h (1 hunks)
  • src/wallet/walletdb.cpp (2 hunks)
  • test/functional/feature_dbcrash.py (2 hunks)
  • test/functional/wallet_basic.py (1 hunks)
  • test/functional/wallet_listreceivedby.py (1 hunks)
💤 Files with no reviewable changes (1)
  • src/wallet/bdb.cpp
🚧 Files skipped from review as they are similar to previous changes (5)
  • test/functional/wallet_listreceivedby.py
  • src/interfaces/wallet.h
  • test/functional/wallet_basic.py
  • src/wallet/walletdb.cpp
  • test/functional/feature_dbcrash.py
🧰 Additional context used
🧬 Code Definitions (4)
src/wallet/wallet.h (2)
src/wallet/interfaces.cpp (10)
  • dest (181-185)
  • dest (181-181)
  • dest (194-197)
  • dest (194-194)
  • dest (198-201)
  • dest (198-198)
  • dest (202-220)
  • dest (202-205)
  • dest (235-239)
  • dest (235-235)
src/interfaces/wallet.h (5)
  • dest (119-119)
  • dest (125-125)
  • dest (128-128)
  • dest (131-134)
  • dest (143-143)
src/wallet/wallet.cpp (1)
src/wallet/wallet.h (7)
  • func (819-819)
  • filter (807-807)
  • label (237-240)
  • label (237-237)
  • label (757-757)
  • label (827-827)
  • purpose (812-812)
src/wallet/rpcwallet.cpp (4)
src/wallet/wallet.h (10)
  • label (237-240)
  • label (237-237)
  • label (757-757)
  • label (827-827)
  • wallet (414-414)
  • dest (610-610)
  • address (857-857)
  • address (859-859)
  • filter (807-807)
  • func (819-819)
src/wallet/rpc/util.cpp (2)
  • LabelFromValue (116-122)
  • LabelFromValue (116-116)
src/script/standard.cpp (2)
  • ExtractDestination (169-197)
  • ExtractDestination (169-169)
src/core_write.cpp (2)
  • ValueFromAmount (31-42)
  • ValueFromAmount (31-31)
src/wallet/interfaces.cpp (3)
src/wallet/rpcwallet.cpp (7)
  • entry (307-307)
  • entry (1195-1195)
  • entry (1229-1229)
  • entry (1613-1613)
  • entry (3184-3184)
  • dest (3707-3707)
  • dest (3707-3707)
src/interfaces/wallet.h (8)
  • dest (119-119)
  • dest (125-125)
  • dest (128-128)
  • dest (131-134)
  • dest (143-143)
  • name (346-346)
  • name (349-349)
  • label (109-109)
src/wallet/wallet.h (9)
  • dest (610-610)
  • dest (828-828)
  • dest (830-830)
  • dest (861-861)
  • purpose (812-812)
  • label (237-240)
  • label (237-237)
  • label (757-757)
  • label (827-827)
🪛 GitHub Actions: Check Merge Fast-Forward Only
src/wallet/rpcwallet.cpp

[error] 1-1: Merge conflict in src/wallet/rpcwallet.cpp. Automatic merge failed; fix conflicts and then commit the result.

🪛 Cppcheck (2.10-2)
src/wallet/interfaces.cpp

[error] 225-225: Syntax Error

(internalAstError)

🔇 Additional comments (26)
src/wallet/interfaces.cpp (4)

208-209: Improved error handling using FindAddressBookEntry

The code now uses FindAddressBookEntry with allow_change=false to check if an address exists in the address book, providing clearer error handling with an early return if the address is not found.


211-212: Better encapsulation with address book entry object

Using entry->GetLabel() instead of directly accessing label data through an iterator improves encapsulation and ensures consistent access patterns.


217-218: Consistent access pattern for address book data

Retrieving the purpose field via entry->purpose maintains consistency with the updated approach to address book data access.


221-229: Enhanced method signature and implementation using ForEachAddrBookEntry

The getAddresses method has been improved in two ways:

  1. The method is now marked const, correctly indicating it doesn't modify the wallet state
  2. The implementation now uses the new ForEachAddrBookEntry method, which simplifies the code by replacing manual iteration with a callback-based approach

This refactoring makes the code more maintainable and follows better API design practices.

🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 225-225: Syntax Error

(internalAstError)

src/wallet/wallet.h (3)

797-802: Well-designed filter struct for address book operations

The new AddrBookFilter struct provides a flexible way to filter address book entries with:

  • Optional label filtering via m_op_label
  • Control over including change addresses via ignore_change

This is a good design choice that allows for extensible filtering capabilities while maintaining backward compatibility.


804-807: New flexible method for retrieving address book destinations

The ListAddrBookAddresses method provides a clean API for retrieving filtered address book entries, replacing the previous GetLabelAddresses method with a more versatile solution that allows filtering by multiple criteria.


809-812: New utility method for listing address book labels by purpose

The ListAddrBookLabels method exposes a useful capability to retrieve all labels for a given purpose, making it easier for callers to work with address book data in a structured way.

src/wallet/wallet.cpp (3)

2903-2909: Clean implementation of a generic address book iterator.

This method provides a simple but powerful abstraction for iterating over address book entries, supporting the application of custom operations through the callback function parameter. This is a good example of the Iterator pattern that promotes code reuse and modularity.


2911-2925: Well-designed address filtering implementation.

This method effectively leverages the ForEachAddrBookEntry function to filter addresses based on optional criteria. The use of a lambda function to apply filtering logic is clean and the implementation correctly handles both the case when a filter is provided and when it's not.


2927-2939: Good implementation for retrieving unique labels.

This method efficiently collects unique labels from the address book for a specific purpose. Using a set data structure ensures uniqueness of returned labels and skipping change addresses is the correct behavior for this use case.

src/wallet/rpcwallet.cpp (16)

543-543: Use of a local vector to store addresses
This change is straightforward and does not raise any concerns.


548-548: Switched from old address retrieval method to ListAddrBookAddresses
This looks correct and consistent with the new address book approach.


559-559: Emplacing the single address
No issues found, the logic is straightforward.


954-954: Introduction of an optional filtered_address
No issues. This is a clear approach to conditionally filter results.


972-972: Early continue if depth is insufficient
No issues found.


974-974: Loop through transaction outputs
Implementation is correct.


979-979: Conditional check for filtered_address
The logic is aligned with the new optional address filter usage.


984-984: Check ismine filter
No issues, consistent usage with existing filter logic.


1000-1001: Lambda capturing address, label, and purpose
Filtering out change addresses is logical and correct.


1004-1005: Skipping if address is not tallied and fIncludeEmpty is false
No issues.


1007-1008: Check ismine filter
Consistent with the approach for filtering addresses.


1014-1014: Extracting nAmount from mapTally
Logic is correct.


1024-1026: Else block for non-label grouping
Implementation is clear, no issues.


1032-1033: Populate transaction IDs
Logic for enumerating transaction IDs is correct.


1040-1047: Handling filtered_address vs. full address book
This usage of ForEachAddrBookEntry is consistent with the new approach. No concerns.


1050-1051: Handling label-based tally
Implementation to handle label grouping is correct.

knst
knst previously approved these changes Apr 1, 2025
Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

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

utACK c5a70462a8af12a32593b5e5b1227e793f518391

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note for myself: missing AssertLockHeld(cs_wallet); due to non-backported bitcoin#19833

MacroFake and others added 3 commits April 1, 2025 23:42
…letBatch' is created

c318211 walletdb: fix last client version update (furszy)
bda8ebe wallet: don't read db every time that a new WalletBatch is created (furszy)

Pull request description:

  Found it while was working on bitcoin#25297.

  We are performing a db read operation every time that a new `WalletBatch` is created, inside the constructor, just to check if the client version field is inside the db or not.

  As the client version field does not change in the entire db lifecycle, this operation can be done only once: The first time that the db is accessed/opened and the client version value can be cached.

ACKs for top commit:
  achow101:
    ACK c318211
  w0xlt:
    reACK bitcoin@c318211

Tree-SHA512: 7fb780c656e169e8eb21e7212242494a647f6506d6da2cca828703713d440d29c82bec9e7d2c410f37b49361226ccd80846d3eeb8168383d0c2a11d85d73bee2
…ng dust (instead of `acceptnonstdtxn=1`)

1770be7 test: pass `dustrelayfee=0` option for tests using dust (instead of `acceptnonstdtxn=1`) (Sebastian Falbesoner)

Pull request description:

  By specifying the `dustrelayfee=0` option instead of the more generic `acceptnonstdtxn=1`, we can be more specific about what
  part of the transaction is non-standard and can be sure that all other aspects follow the standard policy.
  Note that for the test `feature_dbcrash.py`, the UTXO creation at the start of the test has to be split up to several txs to not exceed the tx standard size limit of 100k vbytes

  https://github.com/bitcoin/bitcoin/blob/4129c1375430dbfe8dd414868c43fceb3d091fc3/src/policy/policy.h#L26-L27

ACKs for top commit:
  MarcoFalke:
    review ACK 1770be7

Tree-SHA512: 5cb852a92883a7443ab7dc15b48efa76b5d1424b6b0da1fa6b075fbe9a83522e3ff60382d36c08d4b07143ed898c115614582474e37837332caaee73b0db0e47
d69045e test: add coverage for 'listreceivedbyaddress' no change addrs return (furszy)
324f00a refactor: 'ListReceived' use optional for filtered address (furszy)
b459fc1 refactor: RPC 'ListReceived', encapsulate m_address_book access (furszy)
fa9f2ab refactor: RPC 'listlabels', encapsulate 'CWallet::ListAddrBookLabels' functionality (furszy)
83e42c4 refactor: use 'ForEachAddrBookEntry' in RPC 'getaddressesbylabel' (furszy)
2b48642 refactor: use ForEachAddrBookEntry in interfaces::getAddresses (furszy)
032842a wallet: implement ForEachAddrBookEntry method (furszy)
09649bc refactor: implement general 'ListAddrBookAddresses' for addressbook destinations lookup (furszy)
192eb1e refactor: getAddress don't access m_address_book, use FindAddressEntry function (furszy)

Pull request description:

  ### Context

  The wallet's `m_address_book` field is being accessed directly from several places across the sources.

  ### Problem

  Code structure wise, we shouldn't be accessing it directly. It could end up being modified by mistake (from a place that has nothing to do with the wallet like an RPC command or the GUI) and cause a bigger issue: like an address book entry 'purpose' string change, which if done badly (from 'send' to 'receive'), could end up in a user sharing a "receive" address that he/she doesn't own.

  ### Solution

  Encapsulate `m_address_book` access inside the wallet.

  -------------------------------------------------------

  Extra Note:

  This is the initial step towards decoupling the address book functionality from the wallet's sources. In other words, the creation of the `AddressBookManager` (which will be coming in a follow-up PR).

ACKs for top commit:
  achow101:
    ACK d69045e
  theStack:
    ACK d69045e ✅
  w0xlt:
    ACK bitcoin@d69045e

Tree-SHA512: dba17acd86f171b4e9af0223bbbcad380048570f6a2f6a92732a51f01abe8806debaf65c9e9e5569fa76a541903cbb50adcb5f56ef77858151c698ae6b218e2a
@vijaydasmp vijaydasmp dismissed stale reviews from knst and UdjinM6 via a7d4127 April 1, 2025 18:24
@vijaydasmp vijaydasmp requested review from UdjinM6 and knst April 2, 2025 16:54
@vijaydasmp
Copy link
Author

Hello @PastaPastaPasta , previously approved by @UdjinM6 @knst, had to rebase due to conflict ,
Requesting review

Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

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

utACK a7d4127

range-diff looks good git range-diff origin/develop..c5a70462a8af12a32593b5e5b1227e793f518391 origin/develop..a7d4127ea87c64d7015c7650c60025f4758fdbe4

@knst knst requested a review from PastaPastaPasta April 2, 2025 17:48
@knst knst added this to the 23 milestone Apr 2, 2025
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.

rebase looks clean

re-utACK a7d4127

@PastaPastaPasta PastaPastaPasta merged commit 0f8c35a into dashpay:develop Apr 3, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants