Skip to content

Conversation

@HalFinneyIsMyHomeBoy
Copy link

Summary

Fixes Issue #60

Added clear error messages when loading a wallet with the wrong seed. Replaces generic BDK errors with actionable messages showing which keychain failed (external/internal) and comparing expected vs stored descriptor checksums.

What Changed

  • New WalletError::DescriptorMismatch error with detailed descriptor comparison
  • Helper functions to detect and extract descriptor mismatch information
  • Added Tests for Memory, Sled, and Postgres storage backends

Example Error

DESCRIPTOR MISMATCH DETECTED

external descriptor mismatch detected.

Expected descriptor:
  Checksum: abc12345

Stored descriptor:
  Checksum: xyz98765

The wallet's stored descriptor doesn't match the descriptor
derived from the current seed. Please verify you're using the correct seed
or reset the wallet data if needed, but verify your wallet backups before resetting.

Key Points

  • Only shows checksums (no sensitive data)
  • Identifies which keychain failed (external/internal)
  • Does not trigger on first-time wallet creation
  • Works across all storage backends

Copy link
Owner

@bennyhodl bennyhodl left a comment

Choose a reason for hiding this comment

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

Please consolidate the commits to 1 commit as well

.load_wallet_async(&mut storage)
.await
.map_err(|e| WalletError::WalletPersistanceError(e.to_string()))?;
.map_err(|e| {
Copy link
Owner

Choose a reason for hiding this comment

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

Should be using the errors provided from BDK.

We can extract the LoadError returned from load_wallet_async()

https://docs.rs/bdk_wallet/latest/bdk_wallet/enum.LoadWithPersistError.html

InvalidDerivationIndex,
#[error("Invalid secret key")]
InvalidSecretKey,
#[error(
Copy link
Owner

Choose a reason for hiding this comment

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

I am not a fan of multi-line comments. It becomes hard to match against in other environments. Such as typescript bindings.

I would prefer: The persisted descriptor does not match the provided descriptor. and the include expected and stored in the body.

@@ -0,0 +1,194 @@
mod test_util;
Copy link
Owner

Choose a reason for hiding this comment

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

I try to keep the tests folder for full integration tests with a DDK instance.

These tests can be moved to the wallet module as unit tests.

const MIN_FEERATE: u32 = 253;

/// Helper function to extract the checksum from a descriptor string.
fn extract_descriptor_checksum(descriptor: &str) -> String {
Copy link
Owner

Choose a reason for hiding this comment

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

String matching seems a bit overkill and dangerous to check the error against.

We should be using the provided errors from BDK. If you would like to do extra validation or visibility please use the Descriptor<Pk> struct from the bdk crate.

From that check, we should make sure that we are using a DLC compatible descriptor spending type.

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