Skip to content

Commit 4f81e0d

Browse files
authored
chore: Drop unused lookahead (#288)
Thats basically what the gap limit is doing already and its not used anyway.
1 parent 6f6657e commit 4f81e0d

File tree

3 files changed

+1
-41
lines changed

3 files changed

+1
-41
lines changed

key-wallet/CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ let managed_account = ManagedAccount::from_account(&account);
187187
```rust
188188
// Pre-generate addresses for performance
189189
let pool = &mut managed_account.account_type.receive_pool_mut()?;
190-
pool.ensure_addresses_generated(current_index + lookahead)?;
190+
pool.ensure_addresses_generated(current_index + gap_limit)?;
191191
```
192192

193193
### 3. Transaction Checking Pattern

key-wallet/src/derivation.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,6 @@ pub struct DerivationStrategy {
363363
base_path: DerivationPath,
364364
/// Gap limit for address discovery
365365
gap_limit: u32,
366-
/// Lookahead window
367-
lookahead: u32,
368366
}
369367

370368
impl DerivationStrategy {
@@ -373,7 +371,6 @@ impl DerivationStrategy {
373371
Self {
374372
base_path,
375373
gap_limit: 20,
376-
lookahead: 20,
377374
}
378375
}
379376

@@ -383,12 +380,6 @@ impl DerivationStrategy {
383380
self
384381
}
385382

386-
/// Set the lookahead window
387-
pub fn with_lookahead(mut self, lookahead: u32) -> Self {
388-
self.lookahead = lookahead;
389-
self
390-
}
391-
392383
/// Derive a batch of addresses
393384
pub fn derive_batch<C: secp256k1::Signing>(
394385
&self,

key-wallet/src/managed_account/address_pool.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,6 @@ pub struct AddressPool {
346346
pub highest_generated: Option<u32>,
347347
/// Highest used index
348348
pub highest_used: Option<u32>,
349-
/// Lookahead window for performance
350-
pub lookahead_size: u32,
351349
/// Address type preference
352350
pub address_type: AddressType,
353351
}
@@ -389,7 +387,6 @@ impl AddressPool {
389387
used_indices: HashSet::new(),
390388
highest_generated: None,
391389
highest_used: None,
392-
lookahead_size: gap_limit * 2,
393390
address_type: AddressType::P2pkh,
394391
}
395392
}
@@ -899,23 +896,6 @@ impl AddressPool {
899896
Ok(new_addresses)
900897
}
901898

902-
/// Generate lookahead addresses for performance
903-
pub fn generate_lookahead(&mut self, key_source: &KeySource) -> Result<Vec<Address>> {
904-
let target = match self.highest_used {
905-
None => self.lookahead_size,
906-
Some(highest) => highest + self.lookahead_size + 1,
907-
};
908-
909-
let mut new_addresses = Vec::new();
910-
while self.highest_generated.unwrap_or(0) < target {
911-
let next_index = self.highest_generated.map(|h| h + 1).unwrap_or(0);
912-
let address = self.generate_address_at_index(next_index, key_source, true)?;
913-
new_addresses.push(address);
914-
}
915-
916-
Ok(new_addresses)
917-
}
918-
919899
/// Set a custom label for an address
920900
pub fn set_address_label(&mut self, address: &Address, label: String) -> bool {
921901
if let Some(info) = self.address_info_mut(address) {
@@ -1040,7 +1020,6 @@ pub struct AddressPoolBuilder {
10401020
pool_type: AddressPoolType,
10411021
gap_limit: u32,
10421022
network: Network,
1043-
lookahead_size: u32,
10441023
address_type: AddressType,
10451024
key_source: Option<KeySource>,
10461025
}
@@ -1053,7 +1032,6 @@ impl AddressPoolBuilder {
10531032
pool_type: AddressPoolType::External,
10541033
gap_limit: DEFAULT_EXTERNAL_GAP_LIMIT,
10551034
network: Network::Dash,
1056-
lookahead_size: 40,
10571035
address_type: AddressType::P2pkh,
10581036
key_source: None,
10591037
}
@@ -1093,12 +1071,6 @@ impl AddressPoolBuilder {
10931071
self
10941072
}
10951073

1096-
/// Set the lookahead size
1097-
pub fn lookahead(mut self, size: u32) -> Self {
1098-
self.lookahead_size = size;
1099-
self
1100-
}
1101-
11021074
/// Set the address type
11031075
pub fn address_type(mut self, addr_type: AddressType) -> Self {
11041076
self.address_type = addr_type;
@@ -1122,7 +1094,6 @@ impl AddressPoolBuilder {
11221094
self.gap_limit,
11231095
self.network,
11241096
);
1125-
pool.lookahead_size = self.lookahead_size;
11261097
pool.address_type = self.address_type;
11271098

11281099
// Generate addresses if a key source was provided
@@ -1281,15 +1252,13 @@ mod tests {
12811252
.internal(true)
12821253
.gap_limit(10)
12831254
.network(Network::Testnet)
1284-
.lookahead(20)
12851255
.address_type(AddressType::P2pkh)
12861256
.build()
12871257
.unwrap();
12881258

12891259
assert!(pool.is_internal());
12901260
assert_eq!(pool.gap_limit, 10);
12911261
assert_eq!(pool.network, Network::Testnet);
1292-
assert_eq!(pool.lookahead_size, 20);
12931262
}
12941263

12951264
#[test]

0 commit comments

Comments
 (0)