Skip to content

Commit

Permalink
speed up other search only used in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Jun 20, 2024
1 parent 1e935d7 commit 3315ac6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions base_layer/core/src/transactions/key_manager/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,20 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static

let current_index = km.key_index();

for i in 0u64..current_index + TRANSACTION_KEY_MANAGER_MAX_SEARCH_DEPTH {
let public_key = PublicKey::from_secret_key(&km.derive_key(i)?.key);
for i in 0u64..TRANSACTION_KEY_MANAGER_MAX_SEARCH_DEPTH {
let index = current_index + i;
let public_key = PublicKey::from_secret_key(&km.derive_key(index)?.key);
if public_key == *key {
trace!(target: LOG_TARGET, "Key found in {} Key Chain at index {}", branch, i);
return Ok(i);
return Ok(index);
}
if i <= current_index && i != 0u64 {
let index = current_index - i;
let public_key = PublicKey::from_secret_key(&km.derive_key(index)?.key);
if public_key == *key {
trace!(target: LOG_TARGET, "Key found in {} Key Chain at index {}", branch, index);
return Ok(index);
}
}
}

Expand All @@ -373,7 +382,7 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
trace!(target: LOG_TARGET, "Key found in {} Key Chain at index {}", branch, index);
return Ok(index);
}
if i <= current_index {
if i <= current_index && i != 0u64 {
let index = current_index - i;
let private_key = &km.derive_key(index)?.key;
if private_key == key {
Expand Down

0 comments on commit 3315ac6

Please sign in to comment.