Skip to content

Commit

Permalink
[CHIA-1357] Correctly set start_index in create_more_puzzle_hashes (
Browse files Browse the repository at this point in the history
#18571)

Correctly set `start_index` in `create_more_puzzle_hashes`
  • Loading branch information
Quexington authored Sep 10, 2024
1 parent 2f3e9f1 commit 6a11898
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions chia/wallet/wallet_state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ async def create_more_puzzle_hashes(

# iterate all wallets that need derived keys and establish the start
# index for all of them
start_index: int = 0
start_index_by_wallet: Dict[uint32, int] = {}
last_index = unused + to_generate
for wallet_id in targets:
Expand All @@ -445,30 +444,31 @@ async def create_more_puzzle_hashes(
last: Optional[uint32] = await self.puzzle_store.get_last_derivation_path_for_wallet(wallet_id)
if last is not None:
if last + 1 >= last_index:
self.log.debug(f"Nothing to create for for wallet_id: {wallet_id}, index: {start_index}")
self.log.debug(f"Nothing to create for for wallet_id: {wallet_id}, index: {last_index}")
continue
start_index = min(start_index, last + 1)
start_index_by_wallet[wallet_id] = last + 1
else:
start_index_by_wallet[wallet_id] = 0

if len(start_index_by_wallet) == 0:
return

# now derive the keysfrom start_index to last_index
lowest_start_index = min(start_index_by_wallet.values())

# now derive the keysfrom lowest_start_index to last_index
# these maps derivation index to public key
hardened_keys: Dict[int, G1Element] = {}
unhardened_keys: Dict[int, G1Element] = {}

if self.private_key is not None:
# Hardened
intermediate_sk = master_sk_to_wallet_sk_intermediate(self.private_key)
for index in range(start_index, last_index):
for index in range(lowest_start_index, last_index):
hardened_keys[index] = _derive_path(intermediate_sk, [index]).get_g1()

# Unhardened
intermediate_pk_un = master_pk_to_wallet_pk_unhardened_intermediate(self.root_pubkey)
for index in range(start_index, last_index):
for index in range(lowest_start_index, last_index):
unhardened_keys[index] = _derive_pk_unhardened(intermediate_pk_un, [index])

for wallet_id, start_index in start_index_by_wallet.items():
Expand Down

0 comments on commit 6a11898

Please sign in to comment.