Skip to content

feat: add optional birthday#6975

Merged
SWvheerden merged 3 commits intotari-project:developmentfrom
SWvheerden:sw_wallet_birthday
Apr 22, 2025
Merged

feat: add optional birthday#6975
SWvheerden merged 3 commits intotari-project:developmentfrom
SWvheerden:sw_wallet_birthday

Conversation

@SWvheerden
Copy link
Copy Markdown
Collaborator

@SWvheerden SWvheerden commented Apr 22, 2025

Description

Allows users to specify the wallet birthday

Summary by CodeRabbit

  • New Features
    • Added support for specifying an optional wallet birthday when creating or exporting wallets using view and spend keys.
    • Wallet birthday can be set via a command-line argument or interactively during wallet setup.
    • Exported view and spend key files now include the wallet birthday.
  • Refactor
    • Improved logic for determining the scanning start point during wallet initialization, now considering the wallet birthday.

@SWvheerden SWvheerden requested a review from a team as a code owner April 22, 2025 11:14
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 22, 2025

Walkthrough

The changes introduce support for an optional "birthday" parameter throughout the Minotari console wallet. This parameter can be provided via the CLI, interactively prompted during wallet initialization, and is now included in relevant wallet data structures. The wallet's birthday is also serialized when exporting view and spend keys, and is used to determine the starting point for UTXO scanning. Logic and method signatures are updated to propagate this optional birthday value, ensuring it is consistently available and utilized across wallet creation, export, and scanning operations.

Changes

File(s) Change Summary
applications/minotari_console_wallet/src/cli.rs Added an optional birthday field (Option<u16>) to the Cli struct, allowing users to specify a birthday via a CLI flag.
applications/minotari_console_wallet/src/init/mod.rs Modified WalletBoot::ViewAndSpendKey to include an optional birthday. Updated boot logic to accept, prompt for, and propagate the birthday value. Adjusted function pattern matching and wallet type construction to handle the new field. Imported dialoguer::Input as InputPrompt for interactive prompts.
base_layer/common_types/src/wallet_types.rs Added an optional birthday field (Option<u16>) to the ProvidedKeysWallet struct.
applications/minotari_console_wallet/src/lib.rs
integration_tests/src/wallet_process.rs
Added initialization of the birthday field to None in the construction of Cli struct instances within wallet startup and test code.
applications/minotari_console_wallet/src/automation/commands.rs Updated export logic to retrieve and include the wallet's birthday in the exported view and spend key JSON file and console output. Added a birthday field to the serialized ViewKeyFile struct.
base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs Refactored UTXO scanning logic to accept an optional birthday parameter when determining the scanning start point. Updated get_scanning_start_header_height_hash to use the provided birthday if available, or fetch from the database otherwise. Removed the hardcoded use of height 0 for ProvidedKeys wallets, centralizing and parameterizing start point logic. Updated method signature to accept the birthday parameter.
base_layer/wallet/tests/transaction_service_tests/service.rs Added birthday: None to ProvidedKeysWallet struct initialization in transaction service test setup.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant WalletInit
    participant WalletDB
    participant UTXOScanner

    User->>CLI: Start wallet with --birthday or interactively
    CLI->>WalletInit: Passes birthday (if provided)
    WalletInit->>WalletDB: Stores/uses birthday in wallet creation
    WalletInit->>UTXOScanner: Passes birthday for scanning start
    UTXOScanner->>WalletDB: Uses birthday to determine scan height
    UTXOScanner->>CLI: Scanning starts from birthday-derived block
Loading

Poem

In the wallet’s warren, birthdays now appear,
A number to remember, a date we hold dear.
From CLI to scanning, the value hops along,
Exported in secrets, where birthdays belong.
With every new wallet, a fresh start is spun—
Happy birthday, dear wallet, your journey’s begun!
🐰🎂✨


📜 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 fb0c386 and 8f7c637.

📒 Files selected for processing (1)
  • base_layer/wallet/tests/transaction_service_tests/service.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • base_layer/wallet/tests/transaction_service_tests/service.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: ci

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 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
Copy Markdown
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)
applications/minotari_console_wallet/src/init/mod.rs (1)

795-804: Consider improving the wallet birthday prompt message.

The prompt message could be more descriptive to better explain what the wallet birthday represents (block height) and its purpose (scanning starting point).

-                            let mut birthday = InputPrompt::<u16>::new()
-                                .with_prompt("Please enter wallet birth, or enter to skip ")
+                            let mut birthday = InputPrompt::<u16>::new()
+                                .with_prompt("Please enter wallet birthday (block height for scanning), or enter to skip ")
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aa0ce64 and 57e4dca.

📒 Files selected for processing (7)
  • applications/minotari_console_wallet/src/automation/commands.rs (2 hunks)
  • applications/minotari_console_wallet/src/cli.rs (1 hunks)
  • applications/minotari_console_wallet/src/init/mod.rs (7 hunks)
  • applications/minotari_console_wallet/src/lib.rs (1 hunks)
  • base_layer/common_types/src/wallet_types.rs (1 hunks)
  • base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs (2 hunks)
  • integration_tests/src/wallet_process.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
applications/minotari_console_wallet/src/automation/commands.rs (1)
base_layer/key_manager/src/cipher_seed.rs (1)
  • birthday (330-332)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: ci
🔇 Additional comments (15)
applications/minotari_console_wallet/src/lib.rs (1)

110-110: Properly added optional birthday field.

The addition of the optional birthday field set to None is consistent with other changes in the codebase. This ensures the wallet initialization can properly handle the optional birthday parameter introduced for wallet creation and scanning.

base_layer/common_types/src/wallet_types.rs (1)

57-57: Correctly extended ProvidedKeysWallet with optional birthday field.

The addition of the birthday: Option<u16> field to the ProvidedKeysWallet struct provides the necessary data structure support for the wallet birthday feature. The field is appropriately typed as optional and using u16 is suitable for a blockchain height offset or related metric.

integration_tests/src/wallet_process.rs (1)

238-238: Updated test CLI structure with birthday field.

The integration test's default CLI setup has been correctly updated to include the new optional birthday field set to None, ensuring test consistency with the application code.

applications/minotari_console_wallet/src/cli.rs (1)

102-103: Added CLI support for optional wallet birthday parameter.

The new CLI option for birthday has been correctly implemented as an optional u16 with the #[clap(long)] attribute. This allows users to specify the wallet birthday via the --birthday command-line argument, which will be used to determine the starting point for UTXO scanning.

applications/minotari_console_wallet/src/automation/commands.rs (2)

2519-2519: Birthday value retrieved and incorporated into wallet export functionality

The addition of retrieving the wallet birthday from the database integrates well with the broader changes to support wallet birthday throughout the codebase.


2525-2525: Complete wallet birthday support in export functionality

The birthday field has been consistently added to the ViewKeyFile struct, populated when creating the ViewKeyFile instance, and included in console output when not exporting to a file.

Also applies to: 2531-2531, 2542-2542

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

270-274: Refactored wallet scanning to use birthday parameter

The code now properly passes the optional birthday from ProvidedKeys wallet type to the scanning method, while passing None for other wallet types. This creates a more flexible and consistent approach to determining the scanning start point.


748-753: Improved UTXO scanning with wallet birthday support

The method now accepts an optional birthday parameter and implements a fallback mechanism to get the birthday from the database if not provided. This allows for a more consistent scanning approach across wallet types while improving performance by avoiding unnecessary scanning from genesis for recently created wallets.

applications/minotari_console_wallet/src/init/mod.rs (7)

28-28: Appropriate import added for birthday input handling.

The new import dialoguer::Input as InputPrompt is correctly added to support the interactive prompt for wallet birthday.


105-105: Correctly added optional birthday field to ViewAndSpendKey variant.

The WalletBoot::ViewAndSpendKey enum variant has been properly updated to include an optional birthday field of type Option<u16>.


755-755: Birthday correctly passed from CLI arguments.

The boot function now properly returns the birthday value from CLI arguments when creating a wallet from view and spend keys.


845-845: Pattern matching correctly updated for struct variant.

The pattern matching in boot_with_password has been properly updated to match the new struct variant with the birthday field.


861-861: Pattern matching in conditional properly updated.

The condition in prompt_wallet_type has been correctly updated to use the matches! macro with the new struct variant pattern.


866-866: Birthday field correctly extracted in pattern matching.

The pattern matching in prompt_wallet_type now properly extracts the birthday field from the WalletBoot::ViewAndSpendKey variant.


895-895: Birthday correctly propagated to wallet type.

The birthday value is properly passed from the WalletBoot enum to the WalletType::ProvidedKeys struct, ensuring it's available for downstream components.

stringhandler
stringhandler previously approved these changes Apr 22, 2025
@SWvheerden SWvheerden merged commit 264f646 into tari-project:development Apr 22, 2025
13 of 15 checks passed
@SWvheerden SWvheerden deleted the sw_wallet_birthday branch April 22, 2025 13:20
brianp pushed a commit to tari-project/universe that referenced this pull request Apr 25, 2025
Works along with the tari-project/tari#6975

Description
---
Use wallet birthday argument so it won't be necessary to scan utxos from
the genesis block

* For fresh wallets, scans blocks only from last 2 weeks(birthday - 2
weeks)

Additional improvements
---
* When wallet is up to date, it might scan before grpc service started -
in this case it will return `scanned_height: 0`. Require 3 connections
and 10 retries(10 wallet state updates) instead of 2
* Break progress emitter(condition was never true)
* Log out initial wallet scan progress for easier debugging in future

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Added ability to retrieve and display the wallet's birthday (the block
height from which the wallet starts scanning the blockchain).
  - Introduced new methods to access wallet keys and seed words.

- **Improvements**
- Enhanced wallet startup by allowing the blockchain scan to begin from
a specified birthday, improving performance for existing wallets.
- Centralized and streamlined wallet seed retrieval for better
reliability and maintainability.
- Improved wallet scan progress monitoring with more informative logging
and refined completion detection.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@coderabbitai coderabbitai bot mentioned this pull request Sep 18, 2025
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