Repository navigation
feat(key-wallet): extend CoinJoin address pools before the first sync #1105
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
Changes from all commits
9e04ff6
6b53ee7
f7dfad1
fe85a79
ada424d
55ea942
e9e33cd
0980743
dafdb08
842651a
f125f1f
b987720
796ee10
465d0a7
85e5735
775e533
c5f3057
dd9eee1
fab4eba
e9af123
b37ea6c
6578875
1b9fba1
d4ce586
cedb323
c22bce5
17d7b48
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 |
|---|---|---|
|
|
@@ -471,6 +471,12 @@ impl AddressPool { | |
| Ok(new_addresses) | ||
| } | ||
|
|
||
| /// Generate every address up to and including `index` | ||
| pub fn generate_up_to(&mut self, index: u32, key_source: &KeySource) -> Result<Vec<Address>> { | ||
| let next = self.highest_generated.map_or(0, |highest| highest + 1); | ||
| self.generate_addresses((index + 1).saturating_sub(next), key_source, true) | ||
|
Contributor
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. Reject an index that overflows. For As per coding guidelines: “Never panic in library code.”
|
||
| } | ||
|
|
||
| /// Generate a specific address at an index | ||
| pub(crate) fn generate_address_at_index( | ||
| &mut self, | ||
|
|
@@ -1363,6 +1369,27 @@ mod tests { | |
| assert_eq!(pool.addresses.len(), 10); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_generate_up_to() { | ||
| let base_path = DerivationPath::from(vec![ChildNumber::from_normal_idx(0).unwrap()]); | ||
| let key_source = test_key_source(); | ||
| let mut pool = AddressPool::new( | ||
| base_path, | ||
| AddressPoolType::External, | ||
| 5, | ||
| Network::Testnet, | ||
| &key_source, | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| assert_eq!(pool.generate_up_to(29, &key_source).unwrap().len(), 25); | ||
| assert_eq!(pool.highest_generated, Some(29)); | ||
| assert_eq!(pool.addresses.len(), 30); | ||
|
|
||
| assert!(pool.generate_up_to(10, &key_source).unwrap().is_empty()); | ||
| assert_eq!(pool.highest_generated, Some(29)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_address_usage() { | ||
| let base_path = DerivationPath::from(vec![ChildNumber::from_normal_idx(0).unwrap()]); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -614,6 +614,30 @@ impl ManagedWalletInfo { | |
|
|
||
| address | ||
| } | ||
|
|
||
| /// Derive both pools of every CoinJoin account up to and including `last_index`. | ||
| /// | ||
| /// Call it on fresh wallet state, before the first sync from birth: blocks | ||
| /// already processed are not scanned again for the new addresses. | ||
| pub fn extend_coinjoin_pools( | ||
| &mut self, | ||
| wallet: &Wallet, | ||
| last_index: u32, | ||
| ) -> crate::error::Result<()> { | ||
|
Comment on lines
+622
to
+626
Contributor
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. Reject excessive recovery depths. The method accepts depths of 25,000 or more and can derive an unbounded number of addresses on both chains. A large input can exhaust memory or block the caller for a long time. Reject As per coding guidelines: “Limit pre-generation to reasonable amounts.”
|
||
| for (index, account) in self.accounts.coinjoin_accounts.iter_mut() { | ||
|
Contributor
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. Reject wallets without a CoinJoin account. If
|
||
| let key_source = wallet.key_source_for_account(crate::AccountType::CoinJoin { | ||
| index: *index, | ||
| }); | ||
|
Comment on lines
+627
to
+630
Contributor
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. Validate the wallet identity and network. If As per coding guidelines: “Never mix mainnet and testnet operations.”
|
||
|
|
||
| for pool in account.managed_account_type_mut().address_pools_mut() { | ||
| pool.generate_up_to(last_index, &key_source)?; | ||
| } | ||
|
|
||
| account.bump_monitor_revision(); | ||
|
Contributor
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. Invalidate in-flight filter batches. Bumping the monitor revision does not change
|
||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| /// Re-export types from account module for convenience | ||
|
|
||
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.
Script executed:
rg -n 'fn prune_unused|fn generate_addresses|fn generate_up_to|highest_generated' key-wallet/src/managed_account/address_pool.rsRepository: dashpay/rust-dashcore
Length of output: 2609
Script executed:
Repository: dashpay/rust-dashcore
Length of output: 5261
Script executed:
Repository: dashpay/rust-dashcore
Length of output: 5234
Script executed:
Repository: dashpay/rust-dashcore
Length of output: 6237
Fill gaps below
highest_generated.prune_unusedcan remove an unused, unreserved index below a later reserved index. It then keeps the later index ashighest_generated.generate_up_tostarts athighest_generated + 1, so it can leave the gap absent and a later sync can miss funds sent to that index.Update
generate_up_toto fill missing entries throughindex, not only append entries afterhighest_generated. The CoinJoin extension is documented for fresh wallet state and has no in-repository caller, so this is a narrower public-API issue rather than a demonstrated failure of that workflow.