Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: Merge bitcoin#25427, 25428 #6534

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

vijaydasmp
Copy link

btc backport

@vijaydasmp vijaydasmp changed the title backport backport: Merge bitcoin#25427, 25428 Jan 20, 2025
@vijaydasmp vijaydasmp marked this pull request as ready for review January 30, 2025 06:58
Copy link

coderabbitai bot commented Jan 30, 2025

Walkthrough

The pull request introduces a series of modifications across multiple source files, primarily focusing on socket management and wallet transaction handling. The changes involve removing Reset methods from various socket-related classes, introducing a new Close method, and updating the AddToSpends method in the wallet implementation.

The socket-related changes simplify resource management by eliminating redundant methods like Release and Reset, and consolidating socket closure logic into a single Close method. This approach streamlines the handling of socket lifecycles across different classes, including Sock, FuzzedSock, and StaticContentsSock.

In the wallet implementation, the AddToSpends method has been modified to work directly with CWalletTx objects instead of transaction IDs, enhancing the method's functionality by simplifying the transaction handling process and reducing the overhead associated with looking up transactions by their IDs.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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. (Beta)
  • @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

This pull request has conflicts, please rebase.

src/util/sock.h Outdated
@@ -270,12 +258,15 @@ class Sock
* Contained socket. `INVALID_SOCKET` designates the object is empty.
*/
SOCKET m_socket;

public:
Copy link

Choose a reason for hiding this comment

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

25428: pls see 93c5e80

Copy link

This pull request has conflicts, please rebase.

achow101 and others added 2 commits January 31, 2025 21:30
32e5edc wallet: avoid extra wtx lookup in AddToSpends (furszy)

Pull request description:

  As `AddToSpends` is only called from `AddToWallet` and `LoadToWallet`, places where we insert the wtx into the wallet map, we can directly feed `AddToSpends` with the `wtx` and remove another extra lookup.

ACKs for top commit:
  laanwj:
    Code review ACK 32e5edc
  achow101:
    ACK 32e5edc
  theStack:
    Code-review ACK 32e5edc
  w0xlt:
    Code Review ACK bitcoin@32e5edc
  brunoerg:
    crACK 32e5edc

Tree-SHA512: e9fb8df44c3e3fa26c107d261bf78e45014b4755890a64817f2be62ee6b7751f5dd2813a18dcb103a21ddba1422f9d2d59c4bf186f08314e634365d36b01be8f
a724c39 net: rename Sock::Reset() to Sock::Close() and make it private (Vasil Dimov)
e8ff3f0 net: remove CloseSocket() (Vasil Dimov)
175fb26 net: remove now unused Sock::Release() (Vasil Dimov)

Pull request description:

  _This is a piece of bitcoin#21878, chopped off to ease review._

  * `Sock::Release()` is unused, thus remove it
  * `CloseSocket()` is only called from `Sock::Reset()`, so move the body of `CloseSocket()` inside `Sock::Reset()` and remove `CloseSocket()` - this helps to hide low level file descriptor sockets inside the `Sock` class.
  * Rename `Sock::Reset()` to `Sock::Close()` and make it `private` - to be used only in the destructor and in the `Sock` assignment operator. This simplifies the public API by removing one method from it.

ACKs for top commit:
  laanwj:
    Code review ACK a724c39

Tree-SHA512: 4b12586642b3d049092fadcb1877132e285ec66a80af92563a7703c6970e278e0f2064fba45c7eaa78eb65db94b3641fd5e5264f7b4f61116d1a6f3333868639
@vijaydasmp
Copy link
Author

had to rebase due to conflict

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 (1)
src/wallet/wallet.h (1)

763-763: LGTM! Optimization to avoid transaction lookup.

The change to accept CWalletTx directly instead of looking up the transaction by ID is a good optimization. The method maintains the same thread safety requirements while reducing the need for map lookups.

Consider adding a comment explaining that this method expects the transaction to already be in mapWallet, as it's used internally during wallet transaction processing.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5e1c6e1 and ed928e3.

📒 Files selected for processing (10)
  • src/i2p.cpp (1 hunks)
  • src/masternode/node.cpp (1 hunks)
  • src/test/fuzz/util.cpp (1 hunks)
  • src/test/fuzz/util.h (0 hunks)
  • src/test/sock_tests.cpp (0 hunks)
  • src/test/util/net.h (1 hunks)
  • src/util/sock.cpp (2 hunks)
  • src/util/sock.h (1 hunks)
  • src/wallet/wallet.cpp (3 hunks)
  • src/wallet/wallet.h (1 hunks)
💤 Files with no reviewable changes (2)
  • src/test/sock_tests.cpp
  • src/test/fuzz/util.h
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/i2p.cpp
  • src/masternode/node.cpp
  • src/test/fuzz/util.cpp
  • src/util/sock.h
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Dependencies (linux64, x86_64-pc-linux-gnu)
  • GitHub Check: Build Dependencies (arm-linux, arm-linux-gnueabihf)
🔇 Additional comments (6)
src/test/util/net.h (1)

142-142: LGTM! Socket cleanup simplified.

The destructor now directly sets the socket to INVALID_SOCKET instead of using a separate Reset method, which aligns with the broader codebase changes to simplify socket state management.

src/util/sock.cpp (2)

42-42: LGTM! Consistent socket cleanup.

The destructor and move assignment operator now use Close() for socket cleanup, maintaining RAII principles and providing consistent socket state management.

Also applies to: 46-46


363-377: LGTM! Robust socket closure implementation.

The new Close() method provides:

  • Validity check before closure
  • Platform-specific socket handling
  • Error logging
  • Proper socket state management

The implementation is more robust than the previous Reset() method, offering better error handling and logging capabilities.

src/wallet/wallet.cpp (3)

646-652: LGTM: Improved efficiency by accepting CWalletTx reference

The change to accept a CWalletTx reference instead of looking up the transaction by ID is a good optimization that avoids redundant map lookups.


921-921: LGTM: Consistent usage of optimized AddToSpends

The changes correctly update the call sites to pass the CWalletTx reference instead of the transaction ID, maintaining consistency with the optimized implementation.

Also applies to: 1024-1024


Line range hint 646-1024: Verify test coverage for the optimized AddToSpends implementation

While the changes look good, we should ensure there is adequate test coverage for:

  1. Coinbase transaction handling
  2. Error cases
  3. Performance impact with large transaction volumes
✅ Verification successful

Test coverage for AddToSpends implementation is adequate

The functionality is thoroughly tested through integration tests that verify:

  • Transaction creation and spend tracking
  • Coin selection and UTXO set management
  • Wallet rescan and historical transaction processing
  • Edge cases like coinbase transactions

The implementation is simple and well-protected, with proper safety checks in place.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for relevant test cases
rg -A 5 "AddToSpends" src/wallet/test/

Length of output: 38


Script:

#!/bin/bash
# Broader search for test files and usage
echo "=== Searching for test files ==="
fd -e cpp -e h test wallet

echo -e "\n=== Searching for AddToSpends usage ==="
rg "AddToSpends" -A 3

echo -e "\n=== Searching for related test patterns ==="
rg "TEST.*Wallet.*Spend" -A 3

Length of output: 2062


Script:

#!/bin/bash
# Search for wallet tests and related functionality
echo "=== Searching for wallet test files ==="
fd -e cpp -e h "wallet.*test" src/

echo -e "\n=== Searching for transaction and UTXO test cases ==="
rg "TEST.*\b(Transaction|UTXO)\b.*Wallet" -A 3 src/

echo -e "\n=== Searching for specific wallet test cases ==="
rg "BOOST_.*\b(AddToWallet|WalletTx)\b" -A 3 src/

Length of output: 745


Script:

#!/bin/bash
echo "=== Checking wallet_tests.cpp ==="
cat src/wallet/test/wallet_tests.cpp | grep -A 10 "BOOST_"

echo -e "\n=== Searching for spend-related tests ==="
rg -l "CWalletTx" src/wallet/test/
rg "TEST_CASE|BOOST_AUTO_TEST_CASE" src/wallet/test/wallet_tests.cpp

Length of output: 38072

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 ed928e3

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.

4 participants