Skip to content

Commit da5f9ec

Browse files
fix:adjust default paths and gap limits to match android/iOS behavior (#156)
* fix: add a BIP32 path to Default wallet creation options * fix: increase gap limits to match Android and iOS defaults * chore: fix special gap limit comment * fix: add BIP32 account 0 to create_accounts_with_passphrase_from_options * style: format to pass fmt * tests: update tests for adding BIP32 to Default wallet * style: add missing , * chore: remove unused import * chore: fix comment in test * fix: lower gap limits based on testing with one old wallet from 2019 * style: fix format
1 parent e44b1fb commit da5f9ec

File tree

8 files changed

+159
-47
lines changed

8 files changed

+159
-47
lines changed

key-wallet-manager/tests/integration_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ fn test_account_management() {
6262
);
6363
assert!(result.is_ok());
6464

65-
// Get accounts from wallet - Default creates 7 accounts, plus the one we added
65+
// Get accounts from wallet - Default creates 8 accounts, plus the one we added
6666
let accounts = manager.get_accounts(&wallet_id);
6767
assert!(accounts.is_ok());
68-
assert_eq!(accounts.unwrap().len(), 8); // 7 from Default + 1 we added
68+
assert_eq!(accounts.unwrap().len(), 9); // 8 from Default + 1 we added
6969
}
7070

7171
#[test]

key-wallet/src/gap_limit.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ use serde::{Deserialize, Serialize};
1111
use std::collections::HashSet;
1212

1313
/// Standard gap limit for external addresses (BIP44 recommendation)
14-
pub const DEFAULT_EXTERNAL_GAP_LIMIT: u32 = 20;
14+
pub const DEFAULT_EXTERNAL_GAP_LIMIT: u32 = 30;
1515

1616
/// Standard gap limit for internal (change) addresses
17-
pub const DEFAULT_INTERNAL_GAP_LIMIT: u32 = 10;
17+
pub const DEFAULT_INTERNAL_GAP_LIMIT: u32 = 30;
1818

1919
/// Standard gap limit for CoinJoin addresses
20-
pub const DEFAULT_COINJOIN_GAP_LIMIT: u32 = 10;
20+
pub const DEFAULT_COINJOIN_GAP_LIMIT: u32 = 30;
2121

22+
/// Standard gap limit for special purpose keys (identity, provider keys)
23+
pub const DEFAULT_SPECIAL_GAP_LIMIT: u32 = 5;
2224
/// Maximum gap limit to prevent excessive address generation
2325
pub const MAX_GAP_LIMIT: u32 = 1000;
2426

key-wallet/src/managed_account/address_pool.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
1515

1616
use crate::bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, ExtendedPubKey};
1717
use crate::error::{Error, Result};
18+
use crate::gap_limit::DEFAULT_EXTERNAL_GAP_LIMIT;
1819
use crate::Network;
1920
use dashcore::{Address, AddressType, ScriptBuf};
2021

@@ -1059,7 +1060,7 @@ impl AddressPoolBuilder {
10591060
Self {
10601061
base_path: None,
10611062
pool_type: AddressPoolType::External,
1062-
gap_limit: 20,
1063+
gap_limit: DEFAULT_EXTERNAL_GAP_LIMIT,
10631064
network: Network::Dash,
10641065
lookahead_size: 40,
10651066
address_type: AddressType::P2pkh,

key-wallet/src/managed_account/managed_account_collection.rs

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
//! across different networks in a hierarchical manner.
55
66
use crate::account::account_type::AccountType;
7+
use crate::gap_limit::{
8+
DEFAULT_COINJOIN_GAP_LIMIT, DEFAULT_EXTERNAL_GAP_LIMIT, DEFAULT_INTERNAL_GAP_LIMIT,
9+
DEFAULT_SPECIAL_GAP_LIMIT,
10+
};
711
use crate::managed_account::address_pool::{AddressPool, AddressPoolType};
812
use crate::managed_account::managed_account_type::ManagedAccountType;
913
use crate::managed_account::ManagedAccount;
@@ -329,7 +333,7 @@ impl ManagedAccountCollection {
329333
let external_pool = AddressPool::new(
330334
external_path,
331335
AddressPoolType::External,
332-
20,
336+
DEFAULT_EXTERNAL_GAP_LIMIT,
333337
network,
334338
key_source,
335339
)?;
@@ -339,7 +343,7 @@ impl ManagedAccountCollection {
339343
let internal_pool = AddressPool::new(
340344
internal_path,
341345
AddressPoolType::Internal,
342-
20,
346+
DEFAULT_INTERNAL_GAP_LIMIT,
343347
network,
344348
key_source,
345349
)?;
@@ -356,61 +360,101 @@ impl ManagedAccountCollection {
356360
AccountType::CoinJoin {
357361
index,
358362
} => {
359-
let addresses =
360-
AddressPool::new(base_path, AddressPoolType::Absent, 20, network, key_source)?;
363+
let addresses = AddressPool::new(
364+
base_path,
365+
AddressPoolType::Absent,
366+
DEFAULT_COINJOIN_GAP_LIMIT,
367+
network,
368+
key_source,
369+
)?;
361370
ManagedAccountType::CoinJoin {
362371
index,
363372
addresses,
364373
}
365374
}
366375
AccountType::IdentityRegistration => {
367-
let addresses =
368-
AddressPool::new(base_path, AddressPoolType::Absent, 20, network, key_source)?;
376+
let addresses = AddressPool::new(
377+
base_path,
378+
AddressPoolType::Absent,
379+
DEFAULT_SPECIAL_GAP_LIMIT,
380+
network,
381+
key_source,
382+
)?;
369383
ManagedAccountType::IdentityRegistration {
370384
addresses,
371385
}
372386
}
373387
AccountType::IdentityTopUp {
374388
registration_index,
375389
} => {
376-
let addresses =
377-
AddressPool::new(base_path, AddressPoolType::Absent, 20, network, key_source)?;
390+
let addresses = AddressPool::new(
391+
base_path,
392+
AddressPoolType::Absent,
393+
DEFAULT_SPECIAL_GAP_LIMIT,
394+
network,
395+
key_source,
396+
)?;
378397
ManagedAccountType::IdentityTopUp {
379398
registration_index,
380399
addresses,
381400
}
382401
}
383402
AccountType::IdentityTopUpNotBoundToIdentity => {
384-
let addresses =
385-
AddressPool::new(base_path, AddressPoolType::Absent, 20, network, key_source)?;
403+
let addresses = AddressPool::new(
404+
base_path,
405+
AddressPoolType::Absent,
406+
DEFAULT_SPECIAL_GAP_LIMIT,
407+
network,
408+
key_source,
409+
)?;
386410
ManagedAccountType::IdentityTopUpNotBoundToIdentity {
387411
addresses,
388412
}
389413
}
390414
AccountType::IdentityInvitation => {
391-
let addresses =
392-
AddressPool::new(base_path, AddressPoolType::Absent, 20, network, key_source)?;
415+
let addresses = AddressPool::new(
416+
base_path,
417+
AddressPoolType::Absent,
418+
DEFAULT_SPECIAL_GAP_LIMIT,
419+
network,
420+
key_source,
421+
)?;
393422
ManagedAccountType::IdentityInvitation {
394423
addresses,
395424
}
396425
}
397426
AccountType::ProviderVotingKeys => {
398-
let addresses =
399-
AddressPool::new(base_path, AddressPoolType::Absent, 20, network, key_source)?;
427+
let addresses = AddressPool::new(
428+
base_path,
429+
AddressPoolType::Absent,
430+
DEFAULT_SPECIAL_GAP_LIMIT,
431+
network,
432+
key_source,
433+
)?;
400434
ManagedAccountType::ProviderVotingKeys {
401435
addresses,
402436
}
403437
}
404438
AccountType::ProviderOwnerKeys => {
405-
let addresses =
406-
AddressPool::new(base_path, AddressPoolType::Absent, 20, network, key_source)?;
439+
let addresses = AddressPool::new(
440+
base_path,
441+
AddressPoolType::Absent,
442+
DEFAULT_SPECIAL_GAP_LIMIT,
443+
network,
444+
key_source,
445+
)?;
407446
ManagedAccountType::ProviderOwnerKeys {
408447
addresses,
409448
}
410449
}
411450
AccountType::ProviderOperatorKeys => {
412-
let addresses =
413-
AddressPool::new(base_path, AddressPoolType::Absent, 20, network, key_source)?;
451+
let addresses = AddressPool::new(
452+
base_path,
453+
AddressPoolType::Absent,
454+
DEFAULT_SPECIAL_GAP_LIMIT,
455+
network,
456+
key_source,
457+
)?;
414458
ManagedAccountType::ProviderOperatorKeys {
415459
addresses,
416460
}
@@ -419,7 +463,7 @@ impl ManagedAccountCollection {
419463
let addresses = AddressPool::new(
420464
base_path,
421465
AddressPoolType::AbsentHardened,
422-
20,
466+
DEFAULT_SPECIAL_GAP_LIMIT,
423467
network,
424468
key_source,
425469
)?;

key-wallet/src/managed_account/managed_account_type.rs

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
use crate::account::StandardAccountType;
2+
use crate::gap_limit::{
3+
DEFAULT_COINJOIN_GAP_LIMIT, DEFAULT_EXTERNAL_GAP_LIMIT, DEFAULT_INTERNAL_GAP_LIMIT,
4+
DEFAULT_SPECIAL_GAP_LIMIT,
5+
};
6+
27
use crate::{AccountType, AddressPool, DerivationPath};
38
#[cfg(feature = "bincode")]
49
use bincode_derive::{Decode, Encode};
@@ -356,7 +361,7 @@ impl ManagedAccountType {
356361
let external_pool = AddressPool::new(
357362
external_path,
358363
AddressPoolType::External,
359-
20,
364+
DEFAULT_EXTERNAL_GAP_LIMIT,
360365
network,
361366
key_source,
362367
)?;
@@ -366,7 +371,7 @@ impl ManagedAccountType {
366371
let internal_pool = AddressPool::new(
367372
internal_path,
368373
AddressPoolType::Internal,
369-
20,
374+
DEFAULT_INTERNAL_GAP_LIMIT,
370375
network,
371376
key_source,
372377
)?;
@@ -384,8 +389,13 @@ impl ManagedAccountType {
384389
let path = account_type
385390
.derivation_path(network)
386391
.unwrap_or_else(|_| DerivationPath::master());
387-
let pool =
388-
AddressPool::new(path, AddressPoolType::Absent, 20, network, key_source)?;
392+
let pool = AddressPool::new(
393+
path,
394+
AddressPoolType::Absent,
395+
DEFAULT_COINJOIN_GAP_LIMIT,
396+
network,
397+
key_source,
398+
)?;
389399

390400
Ok(Self::CoinJoin {
391401
index,
@@ -396,8 +406,13 @@ impl ManagedAccountType {
396406
let path = account_type
397407
.derivation_path(network)
398408
.unwrap_or_else(|_| DerivationPath::master());
399-
let pool =
400-
AddressPool::new(path, AddressPoolType::Absent, 20, network, key_source)?;
409+
let pool = AddressPool::new(
410+
path,
411+
AddressPoolType::Absent,
412+
DEFAULT_SPECIAL_GAP_LIMIT,
413+
network,
414+
key_source,
415+
)?;
401416

402417
Ok(Self::IdentityRegistration {
403418
addresses: pool,
@@ -409,8 +424,13 @@ impl ManagedAccountType {
409424
let path = account_type
410425
.derivation_path(network)
411426
.unwrap_or_else(|_| DerivationPath::master());
412-
let pool =
413-
AddressPool::new(path, AddressPoolType::Absent, 20, network, key_source)?;
427+
let pool = AddressPool::new(
428+
path,
429+
AddressPoolType::Absent,
430+
DEFAULT_SPECIAL_GAP_LIMIT,
431+
network,
432+
key_source,
433+
)?;
414434

415435
Ok(Self::IdentityTopUp {
416436
registration_index,
@@ -421,8 +441,13 @@ impl ManagedAccountType {
421441
let path = account_type
422442
.derivation_path(network)
423443
.unwrap_or_else(|_| DerivationPath::master());
424-
let pool =
425-
AddressPool::new(path, AddressPoolType::Absent, 20, network, key_source)?;
444+
let pool = AddressPool::new(
445+
path,
446+
AddressPoolType::Absent,
447+
DEFAULT_SPECIAL_GAP_LIMIT,
448+
network,
449+
key_source,
450+
)?;
426451

427452
Ok(Self::IdentityTopUpNotBoundToIdentity {
428453
addresses: pool,
@@ -432,8 +457,13 @@ impl ManagedAccountType {
432457
let path = account_type
433458
.derivation_path(network)
434459
.unwrap_or_else(|_| DerivationPath::master());
435-
let pool =
436-
AddressPool::new(path, AddressPoolType::Absent, 20, network, key_source)?;
460+
let pool = AddressPool::new(
461+
path,
462+
AddressPoolType::Absent,
463+
DEFAULT_SPECIAL_GAP_LIMIT,
464+
network,
465+
key_source,
466+
)?;
437467

438468
Ok(Self::IdentityInvitation {
439469
addresses: pool,
@@ -443,8 +473,13 @@ impl ManagedAccountType {
443473
let path = account_type
444474
.derivation_path(network)
445475
.unwrap_or_else(|_| DerivationPath::master());
446-
let pool =
447-
AddressPool::new(path, AddressPoolType::Absent, 20, network, key_source)?;
476+
let pool = AddressPool::new(
477+
path,
478+
AddressPoolType::Absent,
479+
DEFAULT_SPECIAL_GAP_LIMIT,
480+
network,
481+
key_source,
482+
)?;
448483

449484
Ok(Self::ProviderVotingKeys {
450485
addresses: pool,
@@ -454,8 +489,13 @@ impl ManagedAccountType {
454489
let path = account_type
455490
.derivation_path(network)
456491
.unwrap_or_else(|_| DerivationPath::master());
457-
let pool =
458-
AddressPool::new(path, AddressPoolType::Absent, 20, network, key_source)?;
492+
let pool = AddressPool::new(
493+
path,
494+
AddressPoolType::Absent,
495+
DEFAULT_SPECIAL_GAP_LIMIT,
496+
network,
497+
key_source,
498+
)?;
459499

460500
Ok(Self::ProviderOwnerKeys {
461501
addresses: pool,
@@ -465,8 +505,13 @@ impl ManagedAccountType {
465505
let path = account_type
466506
.derivation_path(network)
467507
.unwrap_or_else(|_| DerivationPath::master());
468-
let pool =
469-
AddressPool::new(path, AddressPoolType::Absent, 20, network, key_source)?;
508+
let pool = AddressPool::new(
509+
path,
510+
AddressPoolType::Absent,
511+
DEFAULT_SPECIAL_GAP_LIMIT,
512+
network,
513+
key_source,
514+
)?;
470515

471516
Ok(Self::ProviderOperatorKeys {
472517
addresses: pool,
@@ -479,7 +524,7 @@ impl ManagedAccountType {
479524
let pool = AddressPool::new(
480525
path,
481526
AddressPoolType::AbsentHardened,
482-
20,
527+
DEFAULT_SPECIAL_GAP_LIMIT,
483528
network,
484529
key_source,
485530
)?;

key-wallet/src/transaction_checking/transaction_router/tests/routing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ fn test_transaction_affects_multiple_accounts() {
306306
};
307307
wallet.add_account(account_type, network, None).expect("Failed to add account to wallet");
308308

309-
// Add a BIP32 account
309+
// Add another BIP32 account
310310
let account_type = AccountType::Standard {
311-
index: 0,
311+
index: 1,
312312
standard_account_type: StandardAccountType::BIP32Account,
313313
};
314314
wallet.add_account(account_type, network, None).expect("Failed to add account to wallet");

0 commit comments

Comments
 (0)