-
Notifications
You must be signed in to change notification settings - Fork 40
Skip initial full scan for freshly generated wallets #857
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,15 @@ pub struct InternalOnlyMetadata { | |
| /// This is the time that a full scan was completed, this should only happen once | ||
| pub performed_full_scan_at: Option<u64>, | ||
|
|
||
| #[serde(default)] | ||
| /// True only for wallets whose key material was generated by Cove itself | ||
| /// (never imported/typed/scanned in). A freshly generated seed cannot have | ||
| /// on-chain history, so wallets marked here can skip the initial full scan. | ||
| /// | ||
| /// Must only be set at creation time by `WalletMetadata::new_cove_created_wallet`, | ||
| /// never inferred from other state (e.g. `discovery_state`). | ||
| pub generated_in_app: bool, | ||
|
Comment on lines
+82
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a generated wallet is restored from backup or its BDK store is recreated during an address-type switch, Knowledge Base Used: Wallet Manager and Wallet State |
||
|
|
||
| // the type of store used for the wallet | ||
| #[serde(default = "file_store_default")] | ||
| pub store_type: StoreType, | ||
|
|
@@ -281,6 +290,7 @@ impl WalletMetadata { | |
| ) -> Self { | ||
| let mut me = Self::new(name, fingerprint); | ||
| me.set_creation_birthday(); | ||
| me.internal.generated_in_app = true; | ||
| me | ||
| } | ||
|
|
||
|
|
@@ -541,6 +551,84 @@ impl HardwareWalletMetadata { | |
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use std::{collections::HashMap, sync::Once}; | ||
|
|
||
| use cove_device::keychain::{Keychain, KeychainAccess, KeychainError}; | ||
| use parking_lot::Mutex as PMutex; | ||
|
|
||
| #[derive(Debug, Default)] | ||
| struct TestKeychain(PMutex<HashMap<String, String>>); | ||
|
|
||
| impl KeychainAccess for TestKeychain { | ||
| fn save(&self, key: String, value: String) -> Result<(), KeychainError> { | ||
| self.0.lock().insert(key, value); | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn get(&self, key: String) -> Option<String> { | ||
| self.0.lock().get(&key).cloned() | ||
| } | ||
|
|
||
| fn delete(&self, key: String) -> bool { | ||
| self.0.lock().remove(&key).is_some() | ||
| } | ||
| } | ||
|
|
||
| fn setup_test_env() { | ||
| static INIT: Once = Once::new(); | ||
| INIT.call_once(|| { | ||
| Keychain::new(Box::<TestKeychain>::default()); | ||
| }); | ||
|
|
||
| crate::test_support::ensure_tokio_runtime(); | ||
| crate::database::test_support::init_test_database(); | ||
| } | ||
|
|
||
| #[test] | ||
| fn only_cove_created_wallet_is_marked_generated_in_app() { | ||
| let _guard = crate::test_support::global_state_test_lock().blocking_lock(); | ||
| setup_test_env(); | ||
|
|
||
| assert!( | ||
| WalletMetadata::new_cove_created_wallet("test", Some(Fingerprint::default())) | ||
| .internal | ||
| .generated_in_app | ||
| ); | ||
|
|
||
| assert!( | ||
| !WalletMetadata::new_imported_from_mnemonic( | ||
| "test", | ||
| Network::Bitcoin, | ||
| Fingerprint::default() | ||
| ) | ||
| .internal | ||
| .generated_in_app | ||
| ); | ||
|
|
||
| assert!( | ||
| !WalletMetadata::new_for_hardware(WalletId::preview_new_random(), "test", None) | ||
| .internal | ||
| .generated_in_app | ||
| ); | ||
|
|
||
| assert!(!WalletMetadata::new("test", None::<Arc<Fingerprint>>).internal.generated_in_app); | ||
| assert!(!WalletMetadata::preview_new().internal.generated_in_app); | ||
| } | ||
|
|
||
| #[test] | ||
| fn missing_generated_in_app_deserializes_to_false() { | ||
| let _guard = crate::test_support::global_state_test_lock().blocking_lock(); | ||
| setup_test_env(); | ||
|
|
||
| let metadata = | ||
| WalletMetadata::new_cove_created_wallet("test", Some(Fingerprint::default())); | ||
| let mut value = serde_json::to_value(metadata).unwrap(); | ||
| value.get_mut("internal").unwrap().as_object_mut().unwrap().remove("generated_in_app"); | ||
|
|
||
| let deserialized: WalletMetadata = serde_json::from_value(value).unwrap(); | ||
|
|
||
| assert!(!deserialized.internal.generated_in_app); | ||
| } | ||
|
|
||
| #[test] | ||
| fn missing_birthday_deserializes_to_none() { | ||
|
|
@@ -646,6 +734,7 @@ mod tests { | |
| last_seen: Duration::from_secs(20), | ||
| }), | ||
| performed_full_scan_at: Some(30), | ||
| generated_in_app: true, | ||
| store_type: StoreType::FileStore, | ||
| }; | ||
|
|
||
|
|
@@ -656,6 +745,7 @@ mod tests { | |
| assert_eq!(metadata.last_height_fetched, None); | ||
| assert_eq!(metadata.performed_full_scan_at, None); | ||
| assert_eq!(metadata.store_type, StoreType::FileStore); | ||
| assert!(metadata.generated_in_app, "generated_in_app is identity, not scan state"); | ||
| } | ||
|
|
||
| #[test] | ||
|
|
||
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.
When a generated wallet completes its initial incremental scan,
performed_full_scan_atremains unset, so the shared ledger state staysInitialScanIncomplete; this leaves the balance provisional and the UI loading or scanning indefinitely, while manager-level spend readiness can still reject the wallet.Knowledge Base Used: Wallet Manager and Wallet State