Skip to content

feat: change wallet birthday offset #6992

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

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

SWvheerden
Copy link
Collaborator

@SWvheerden SWvheerden commented Apr 25, 2025

Description

changes the wallet birthday offset from 2 weeks to 2 days. Allows users to set it to a custom number if so desired

Summary by CodeRabbit

  • New Features

    • Introduced a configurable "birthday offset" setting that allows users to adjust how many days before the wallet's creation date scanning for transactions begins.
    • Added this new option to wallet configuration and included documentation for it in the sample configuration file.
  • Documentation

    • Updated sample configuration file to describe the new "birthday offset" option.
  • Bug Fixes

    • No user-facing bug fixes included in this release.

@SWvheerden SWvheerden requested a review from a team as a code owner April 25, 2025 11:49
Copy link
Contributor

coderabbitai bot commented Apr 25, 2025

Walkthrough

A new configurable field, birthday_offset, has been introduced throughout the wallet and UTXO scanner components. This field allows the offset in days for UTXO scanning to be set relative to the wallet's birthday, replacing a previously hardcoded value. The offset is now part of the wallet configuration, propagated through service initializers, resource containers, tasks, and builder methods. Related test initializations and configuration documentation have also been updated to reflect this change, enabling dynamic adjustment of the scanning start time.

Changes

File(s) Change Summary
base_layer/wallet/src/config.rs Added birthday_offset field to WalletConfig; updated Default to set birthday_offset: 2.
base_layer/wallet/src/wallet.rs Added config: WalletConfig to Wallet struct; updated start to handle and propagate birthday_offset.
base_layer/wallet/src/utxo_scanner_service/initializer.rs Added birthday_offset to UtxoScannerServiceInitializer; updated constructor and usage to pass the offset.
base_layer/wallet/src/utxo_scanner_service/service.rs Added birthday_offset to UtxoScannerResources; propagated offset into scanner task creation.
base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs Added birthday_offset to UtxoScannerTask; replaced hardcoded offset with configurable field.
base_layer/wallet/src/utxo_scanner_service/uxto_scanner_service_builder.rs Updated builder methods to accept and pass birthday_offset into resources.
base_layer/wallet/tests/transaction_service_tests/service.rs Updated test to pass 14 as birthday_offset to UTXO scanner initializer.
base_layer/wallet/tests/utxo_scanner/mod.rs Updated test to pass 14 as birthday_offset to build_with_resources.
common/config/presets/d_console_wallet.toml Added commented example lines for birthday_offset in wallet config section.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Wallet
    participant UtxoScannerServiceInitializer
    participant UtxoScannerServiceBuilder
    participant UtxoScannerResources
    participant UtxoScannerTask

    User->>Wallet: start(config)
    Wallet->>UtxoScannerServiceInitializer: new(..., config.birthday_offset)
    UtxoScannerServiceInitializer->>UtxoScannerServiceBuilder: build_with_resources(..., birthday_offset)
    UtxoScannerServiceBuilder->>UtxoScannerResources: construct(..., birthday_offset)
    UtxoScannerResources->>UtxoScannerTask: create_task(..., birthday_offset)
    UtxoScannerTask-->>UtxoScannerResources: use birthday_offset for scanning start
Loading

Poem

In fields of code where wallets hop,
A birthday offset, now we swap!
No longer fixed to two weeks' past,
Configurable days—flexible at last!
From config to scanner, the value flows,
Rabbits rejoice as the feature grows.
🐇✨

✨ 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.
    • 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 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
Contributor

@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)
common/config/presets/d_console_wallet.toml (1)

102-103: Configuration option added with clear documentation.

The PR adds a well-documented configuration option for the birthday offset with a default value of 2 days. This provides users the flexibility to customize scanning behavior.

Note that there's a minor typo "defaul" (missing 't') in the comment text, but this won't affect functionality.

-#The defaul offset for scanning from the birthday, it will start at the birthday - the offset
+#The default offset for scanning from the birthday, it will start at the birthday - the offset
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 693cd7a and e2851ac.

📒 Files selected for processing (9)
  • base_layer/wallet/src/config.rs (2 hunks)
  • base_layer/wallet/src/utxo_scanner_service/initializer.rs (3 hunks)
  • base_layer/wallet/src/utxo_scanner_service/service.rs (2 hunks)
  • base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs (2 hunks)
  • base_layer/wallet/src/utxo_scanner_service/uxto_scanner_service_builder.rs (3 hunks)
  • base_layer/wallet/src/wallet.rs (6 hunks)
  • base_layer/wallet/tests/transaction_service_tests/service.rs (1 hunks)
  • base_layer/wallet/tests/utxo_scanner/mod.rs (1 hunks)
  • common/config/presets/d_console_wallet.toml (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs (2)
base_layer/key_manager/src/lib.rs (1)
  • get_birthday_from_unix_epoch_in_seconds (41-43)
base_layer/key_manager/src/cipher_seed.rs (1)
  • birthday (330-332)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: cargo check with stable
  • GitHub Check: ci
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: Cucumber tests / FFI
🔇 Additional comments (24)
base_layer/wallet/src/config.rs (1)

124-125: Well-implemented birthday offset configuration with sensible default

The addition of the birthday_offset field to the WalletConfig struct provides users with the flexibility to configure how many days the wallet should start scanning before the actual birthday. The default value of 2 days (reduced from the previous hardcoded 14 days) seems reasonable for most use cases.

The implementation is clean, with a descriptive comment and appropriate type (u16).

Also applies to: 165-165

base_layer/wallet/tests/transaction_service_tests/service.rs (1)

281-286: Ensure test initializer reflects new configurable birthday_offset
The UtxoScannerServiceInitializer::new call now accepts the birthday_offset parameter. Passing 14 here maintains the original 2-week offset for tests, isolating them from the updated default of 2 days.

base_layer/wallet/tests/utxo_scanner/mod.rs (6)

203-218: Birthday offset parameter properly added to test setup.

The PR correctly adds the explicit birthday offset parameter (14 days) when calling build_with_resources. This ensures test compatibility with the new configurable offset feature.


307-308: Verify consistency between test value and actual offset parameter.

The hardcoded 14u16 value here matches the explicitly passed parameter on line 216, maintaining consistency within the test. This is important as the wallet scanned block detection logic depends on both values matching.


398-399: Confirm consistent offset value across test cases.

The hardcoded value 14 in test_utxo_scanner_recovery_with_restart is consistent with the previously reviewed test cases, ensuring uniform test behavior.


543-543: Consistent offset value in chain restart test case.

The hardcoded value 14 in test_utxo_scanner_recovery_with_restart_and_reorg properly aligns with the other test methods, ensuring tests remain consistent after refactoring.


741-741: Consistent offset value in cache clearing test case.

The cache clearing test case uses the same offset value (14) as the other test methods, maintaining consistency and ensuring accurate test behavior.


851-852: Birthday offset type annotated for clarity.

The use of 14u16 here explicitly indicates the type expected by the birthday offset calculation function, providing clarity for future maintainers.

base_layer/wallet/src/utxo_scanner_service/service.rs (2)

95-107: Birthday offset properly propagated to scanner task.

The birthday offset is correctly added to the UtxoScannerTask when creating a new task. This ensures the configurable parameter is passed through to the component that actually uses it for UTXO scanning calculations.


189-202: Field added to resource struct for birthday offset storage.

The birthday_offset field of type u16 is appropriately added to the UtxoScannerResources struct. This is a clean and backward-compatible way to extend the structure.

base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs (3)

75-85: Field added to task struct for birthday offset.

The birthday_offset field of type u16 is appropriately added to the UtxoScannerTask struct, completing the chain of propagation from config through to the actual scanning logic.


746-766: Updated scanning logic to use configurable offset.

The scanning logic has been successfully updated to use the configurable birthday_offset instead of the previously hardcoded value. The comment has also been updated to reflect the new default of 2 days, aligning with the configuration change.

This change improves flexibility by allowing users to set their preferred scanning range while maintaining the same functionality to avoid potential reorg issues.


777-786: Comprehensive logging message maintained.

The PR preserves the detailed logging message that explains the birthday-to-scanning time conversion, which is important for troubleshooting and understanding wallet recovery behavior.

base_layer/wallet/src/utxo_scanner_service/initializer.rs (4)

50-56: Field addition properly encapsulates the new configuration parameter.

The addition of the birthday_offset field to the UtxoScannerServiceInitializer struct is well-placed and uses an appropriate type (u16) for storing a day-based offset.


61-69: Constructor updated correctly to handle the new parameter.

The constructor has been properly updated to accept the new birthday_offset parameter and initialize it in the struct construction. The parameter is placed at the end of the parameter list, which is a good practice for backward compatibility if this was an external API.


100-100: Parameter extraction looks good.

The birthday_offset is correctly extracted from self to be used in the service initialization.


142-142: Parameter correctly passed to the builder.

The birthday_offset is properly passed to the build_with_resources method of the UtxoScannerService builder, ensuring the configurable value is used throughout the scanning process.

base_layer/wallet/src/utxo_scanner_service/uxto_scanner_service_builder.rs (3)

121-121: Config value correctly propagated to resources.

The wallet config's birthday_offset is properly accessed and passed to the UtxoScannerResources, ensuring the user-defined configuration is respected during UTXO scanning.


157-157: Parameter addition to method signature looks good.

The builder's build_with_resources method has been correctly updated to accept the birthday_offset parameter. Adding it at the end of the parameter list is a good practice for backward compatibility.


170-170: Assignment to resources is correctly implemented.

The birthday_offset parameter is properly assigned to the UtxoScannerResources struct, ensuring the configurable value is available during the UTXO scanning process.

base_layer/wallet/src/wallet.rs (4)

163-163: Good addition of config field to Wallet struct.

Adding the config field to the Wallet struct is a good design choice that allows the wallet instance to reference configuration values after initialization. Making it public allows external components to access these settings if needed.


217-218: Proper cloning of config values.

Cloning the config values when passing them to initializers is a good practice that avoids ownership issues. This ensures the config remains intact for use by subsequent initializers and for storing in the final Wallet struct.

Also applies to: 229-230, 259-260


265-265: Config value correctly passed to scanner initializer.

The birthday_offset value from config is properly passed to the UtxoScannerServiceInitializer, ensuring the configurable offset is used during UTXO scanning.


383-383: Wallet struct properly initialized with config.

The Wallet struct returned by the start method now includes the config field, making the configuration values accessible to consumers of the wallet instance.

Copy link

Test Results (CI)

    3 files    129 suites   57m 21s ⏱️
1 335 tests 1 335 ✅ 0 💤 0 ❌
4 003 runs  4 003 ✅ 0 💤 0 ❌

Results for commit e2851ac.

Copy link

Test Results (Integration tests)

 2 files  11 suites   1h 18m 29s ⏱️
36 tests 32 ✅ 0 💤  4 ❌
44 runs  32 ✅ 0 💤 12 ❌

For more details on these failures, see this check.

Results for commit e2851ac.

Copy link
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

utACK

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.

2 participants