-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: bitcoin#25784, 25878, 25865, 25879 #6550
base: develop
Are you sure you want to change the base?
Conversation
… (now InitWalletFlags) correctly 0cb6d2a Bugfix: Wallet: Document expectations for AddWalletFlags (now InitWalletFlags) correctly (Luke Dashjr) Pull request description: Includes some slight refactoring (return type changed, current status checked) ACKs for top commit: achow101: ACK 0cb6d2a w0xlt: ACK bitcoin@0cb6d2a ryanofsky: Code review ACK 0cb6d2a. This is a clarifying change, and should prevent the InitWalletFlags method being called incorrectly. I left a comment suggestion, but feel free to ignore it. Tree-SHA512: fa18e9471b5e89d35cbc01526e6d4dbe4eee8faa9646847248909af1751b33014a6f9a42fe70a1331c0d73adea79008b8fc3ae2b51a641eba3e36d5c631327f6
d58ebb1
to
cbc0ce6
Compare
02dea9a tests: Use mocktime for wallet encryption timeout (Andrew Chow) Pull request description: The intermittent wallet_encryption.py failures are related to differences in time between python and std::chrono. We can avoid this entirely by using mocktime. This also allows us to test for the exact unlocking time rather than that it is greater than expected. Fixes bitcoin#25482 ACKs for top commit: MarcoFalke: review ACK 02dea9a vasild: ACK 02dea9a Tree-SHA512: 5a5489f5cd2569c824bf5b3d839be0c632ed27627c0eff65dda63c143a8d1174fe3252acba8102b4242a9ddf42d82bfe79babad68f1beeb83eb251386058e039
… (immediate tx relay) b21e522 test: speedup wallet tests by whitelisting peers (immediate tx relay) (Sebastian Falbesoner) Pull request description: In the course of testing bitcoin#25297 by running all wallet-related functional tests (see bitcoin#25297 (comment)), I noticed that the run-time of those tests vary a lot between runs, in fact too much for a useful comparison. This PR fixes this by making the tests both more deterministic and also faster, using the good ol' immediate tx relay trick (parameter `[email protected]`). master branch: ``` wallet_abandonconflict.py --descriptors | ✓ Passed | 7 s wallet_abandonconflict.py --legacy-wallet | ✓ Passed | 23 s wallet_balance.py --descriptors | ✓ Passed | 17 s wallet_balance.py --legacy-wallet | ✓ Passed | 21 s wallet_basic.py --descriptors | ✓ Passed | 32 s wallet_basic.py --legacy-wallet | ✓ Passed | 56 s wallet_bumpfee.py --descriptors | ✓ Passed | 44 s wallet_bumpfee.py --legacy-wallet | ✓ Passed | 45 s wallet_groups.py --descriptors | ✓ Passed | 89 s wallet_groups.py --legacy-wallet | ✓ Passed | 94 s wallet_hd.py --descriptors | ✓ Passed | 7 s wallet_hd.py --legacy-wallet | ✓ Passed | 13 s wallet_importdescriptors.py --descriptors | ✓ Passed | 26 s wallet_listreceivedby.py --descriptors | ✓ Passed | 28 s wallet_listreceivedby.py --legacy-wallet | ✓ Passed | 18 s ALL | ✓ Passed | 520 s (accumulated) Runtime: 526 s ``` PR branch: ``` wallet_abandonconflict.py --descriptors | ✓ Passed | 7 s wallet_abandonconflict.py --legacy-wallet | ✓ Passed | 11 s wallet_balance.py --descriptors | ✓ Passed | 8 s wallet_balance.py --legacy-wallet | ✓ Passed | 8 s wallet_basic.py --descriptors | ✓ Passed | 29 s wallet_basic.py --legacy-wallet | ✓ Passed | 36 s wallet_bumpfee.py --descriptors | ✓ Passed | 39 s wallet_bumpfee.py --legacy-wallet | ✓ Passed | 32 s wallet_groups.py --descriptors | ✓ Passed | 39 s wallet_groups.py --legacy-wallet | ✓ Passed | 41 s wallet_hd.py --descriptors | ✓ Passed | 8 s wallet_hd.py --legacy-wallet | ✓ Passed | 11 s wallet_importdescriptors.py --descriptors | ✓ Passed | 17 s wallet_listreceivedby.py --descriptors | ✓ Passed | 7 s wallet_listreceivedby.py --legacy-wallet | ✓ Passed | 9 s ALL | ✓ Passed | 302 s (accumulated) Runtime: 309 s ``` Note that an alternative approach could be to whitelist peers by default for nodes in the functional test framework and only enable the trickle relay for the few tests where it's really needed. ACKs for top commit: naumenkogs: utACK b21e522 Tree-SHA512: ac3c8f8f5a401d1b6af60ece9c77e72449f18920c2cb4a1bd65fb4d62cf428779ebf4e1d29009a882977b2252922df4e7183541e0da8de932f8cd479149e8a86
…er type fa95315 Use new Join() helper for ListBlockFilterTypes() (MacroFake) fa1c716 Make Join() util work with any container type (MacroFake) faf8da3 Remove Join() helper only used in tests (MacroFake) Pull request description: This allows to drop some code ACKs for top commit: naumenkogs: ACK fa95315 stickies-v: ACK [fa95315](bitcoin@fa95315) Tree-SHA512: efd65b65722f46b221bd53140ff22bd8e45adc83617980233f28f695be3108a6ab01affd751d715134ffcb9762228ba8952e9467e590cff022c83e0f5404cb74
d8d1810
to
8f73b41
Compare
WalkthroughThe pull request introduces multiple changes across the codebase. In the core logic, the concatenation of block filter type names in blockfilter.cpp is simplified by replacing the string stream approach with a utility Join function, which now resides in the modified util/string.h file. The Join function itself has been generalized to work with any container using a range-based loop. In the wallet modules, the method for initializing wallet flags has been refactored: the previous AddWalletFlags method has been replaced with InitWalletFlags, which now includes additional assertions and validations. In addition, several functional tests related to wallet operations have been updated to include a whitelisting argument ("[email protected]") in their setup parameters, and wallet encryption tests have moved from range assertions to strict equality checks for unlock times. These changes update both functionality and testing configurations as documented in the pull request. ✨ Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (14)
src/blockfilter.cpp
(2 hunks)src/test/util_tests.cpp
(1 hunks)src/util/string.h
(1 hunks)src/wallet/wallet.cpp
(2 hunks)src/wallet/wallet.h
(1 hunks)test/functional/wallet_abandonconflict.py
(1 hunks)test/functional/wallet_balance.py
(1 hunks)test/functional/wallet_basic.py
(1 hunks)test/functional/wallet_encryption.py
(2 hunks)test/functional/wallet_groups.py
(1 hunks)test/functional/wallet_hd.py
(1 hunks)test/functional/wallet_importdescriptors.py
(1 hunks)test/functional/wallet_listreceivedby.py
(1 hunks)test/functional/wallet_listsinceblock.py
(1 hunks)
🔇 Additional comments (20)
src/util/string.h (3)
60-67
: Documentation accurately reflects the enhanced functionality.The updated documentation clearly describes the generic container support and provides accurate parameter descriptions.
68-79
: Well-designed template implementation with improved efficiency.The changes improve the Join function in several ways:
- Generic container support through template parameter
C
- More efficient implementation using range-based for loop
- Cleaner control flow with boolean flag instead of index checking
81-85
: Consistent implementation of the simplified overload.The overload correctly maintains consistency with the primary implementation.
test/functional/wallet_encryption.py (2)
78-84
: Improved test determinism with mocktime.The changes enhance test reliability by:
- Using mocktime instead of real time
- Using exact equality assertions instead of range checks
87-91
: Consistent time checking approach.The same pattern of using mocktime and exact equality is maintained for the second test case.
src/blockfilter.cpp (2)
15-15
: Appropriate header inclusion for string utilities.The addition of string.h header supports the use of the Join function.
182-182
: Elegant simplification of ListBlockFilterTypes.The implementation is improved by:
- Using the generic Join function instead of manual string concatenation
- More maintainable and readable code
- Efficient lambda usage to extract filter type names
test/functional/wallet_listreceivedby.py (1)
20-21
: Enhanced test reliability with whitelist configuration.The addition of the whitelist configuration improves test reliability by speeding up transaction relay and mempool synchronization between nodes.
test/functional/wallet_groups.py (1)
28-30
: LGTM! Well-documented peer whitelisting.The addition of peer whitelisting with clear documentation improves test performance by speeding up transaction relay and mempool synchronization.
test/functional/wallet_abandonconflict.py (1)
27-29
: LGTM! Consistent peer whitelisting implementation.The addition of peer whitelisting matches the pattern seen in other test files and will help improve test performance.
test/functional/wallet_balance.py (1)
56-58
: LGTM! Consistent peer whitelisting implementation.The addition of peer whitelisting follows the same pattern as other test files and will enhance test performance.
test/functional/wallet_hd.py (1)
22-24
: LGTM! Consistent peer whitelisting implementation.The addition of peer whitelisting maintains consistency with other test files and will improve test performance.
test/functional/wallet_listsinceblock.py (1)
25-26
: LGTM! Test configuration updated to improve transaction relay.The addition of the whitelist argument will help speed up transaction relay and mempool synchronization during test execution.
test/functional/wallet_importdescriptors.py (1)
37-39
: LGTM! Test configuration updated to improve transaction relay.The addition of the whitelist argument using a loop is a clean implementation that will help speed up transaction relay and mempool synchronization during test execution.
test/functional/wallet_basic.py (1)
30-30
: LGTM! Test configuration updated to improve transaction relay.The addition of the whitelist argument in both descriptor and non-descriptor paths will help speed up transaction relay and mempool synchronization during test execution.
Also applies to: 34-34
src/wallet/wallet.h (1)
1429-1432
: Verify the initialization requirements for wallet flags.The new
InitWalletFlags
method has strict requirements:
- The flags parameter must be uninitialized (or 0)
- Only known flags may be present
Please ensure that all callers of this method comply with these requirements to prevent potential issues.
Run the following script to verify the usage of
InitWalletFlags
:✅ Verification successful
🏁 Script executed:
#!/bin/bash # Description: Check all callers of InitWalletFlags to ensure they pass uninitialized flags. # Search for InitWalletFlags usage rg -A 5 $'InitWalletFlags' # Search for known flags definition to cross-reference rg -A 10 $'KNOWN_WALLET_FLAGS'Length of output: 2885
Wallet flag initialization conformity verified.
The implementation in CWallet::InitWalletFlags in wallet.cpp enforces the preconditions:
- It asserts that the wallet flags are uninitialized (m_wallet_flags must be 0).
- It asserts that only known flags are provided by comparing (flags & KNOWN_WALLET_FLAGS) with flags.
Additionally, the usage sites (e.g., walletInstance->InitWalletFlags) appear to comply with these requirements.
src/test/util_tests.cpp (2)
248-260
: LGTM! Test cases updated to use explicit container types.The test cases for the Join function have been improved by using explicit container types (std::vector and std::list), which better demonstrates the generic container support. The test coverage is comprehensive, covering empty containers, single elements, and multiple elements with both basic joining and transformation operations.
2755-2799
: LGTM! Comprehensive test coverage for binary file operations.The new test cases for ReadBinaryFile and WriteBinaryFile provide thorough coverage of file operations, including:
- Full file reads
- Partial file reads
- Error handling for non-existent files
- File writing and content verification
The tests properly use RAII for file handling and clean up temporary files appropriately.
src/wallet/wallet.cpp (2)
1770-1784
: LGTM! The newInitWalletFlags
method improves wallet initialization safety.The new method adds important assertions to ensure wallet flags are initialized correctly:
- Verifies that only known wallet flags are being set
- Ensures flags are only set during initial wallet creation
- Validates that current flags are blank before initialization
4781-4782
: LGTM! Proper integration of the new wallet flags initialization.The new
InitWalletFlags
method is correctly called during first run wallet initialization.
/** overwrite all flags by the given uint64_t | ||
returns false if unknown, non-tolerable flags are present */ | ||
bool AddWalletFlags(uint64_t flags); | ||
flags must be uninitialised (or 0) | ||
only known flags may be present */ | ||
void InitWalletFlags(uint64_t flags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add validation against KNOWN_WALLET_FLAGS.
Consider adding validation in the implementation to ensure that:
- The input flags are a subset of
KNOWN_WALLET_FLAGS
- The flags are uninitialized (0) before initialization
Example validation:
void CWallet::InitWalletFlags(uint64_t flags)
{
if (m_wallet_flags != 0) {
throw std::logic_error("InitWalletFlags called with initialized flags");
}
if ((flags & ~KNOWN_WALLET_FLAGS) != 0) {
throw std::logic_error("InitWalletFlags called with unknown flags");
}
m_wallet_flags = flags;
}
Bitcoin Backporting