mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-09-05 02:24:21 -05:00
Merge pull request #12037 from trepca/nft1_puzhash_gen_fix
fix for derivation path generation hogging CPU for NFT wallet
This commit is contained in:
@@ -4,7 +4,7 @@ import logging
|
||||
import time
|
||||
from typing import Any, Dict, List, Optional, Set, Tuple, Type, TypeVar
|
||||
|
||||
from blspy import AugSchemeMPL, G1Element, G2Element
|
||||
from blspy import AugSchemeMPL, G2Element
|
||||
|
||||
from chia.protocols.wallet_protocol import CoinState
|
||||
from chia.server.outbound_message import NodeType
|
||||
@@ -21,12 +21,7 @@ from chia.wallet.derivation_record import DerivationRecord
|
||||
from chia.wallet.lineage_proof import LineageProof
|
||||
from chia.wallet.nft_wallet import nft_puzzles
|
||||
from chia.wallet.nft_wallet.nft_info import NFTCoinInfo, NFTWalletInfo
|
||||
from chia.wallet.nft_wallet.nft_puzzles import (
|
||||
NFT_METADATA_UPDATER,
|
||||
NFT_STATE_LAYER_MOD_HASH,
|
||||
create_ownership_layer_puzzle,
|
||||
get_metadata_and_phs,
|
||||
)
|
||||
from chia.wallet.nft_wallet.nft_puzzles import NFT_METADATA_UPDATER, create_ownership_layer_puzzle, get_metadata_and_phs
|
||||
from chia.wallet.nft_wallet.uncurry_nft import UncurriedNFT
|
||||
from chia.wallet.outer_puzzles import AssetType, construct_puzzle, match_puzzle, solve_puzzle
|
||||
from chia.wallet.payment import Payment
|
||||
@@ -122,10 +117,6 @@ class NFTWallet:
|
||||
def type(cls) -> uint8:
|
||||
return uint8(WalletType.NFT)
|
||||
|
||||
async def get_new_puzzle(self) -> Program:
|
||||
self.log.debug("Getting new puzzle for NFT wallet: %s", self.id())
|
||||
return self.puzzle_for_pk((await self.wallet_state_manager.get_unused_derivation_record(self.id())).pubkey)
|
||||
|
||||
def id(self) -> uint32:
|
||||
return self.wallet_info.id
|
||||
|
||||
@@ -207,7 +198,8 @@ class NFTWallet:
|
||||
] = await self.wallet_state_manager.puzzle_store.get_derivation_record_for_puzzle_hash(p2_puzzle_hash)
|
||||
self.log.debug("Record for %s is: %s", p2_puzzle_hash, derivation_record)
|
||||
if derivation_record is None:
|
||||
raise ValueError(f"Cannot find the DerivationRecord for {p2_puzzle_hash}")
|
||||
self.log.debug(f"Not our NFT, pointing to {p2_puzzle_hash}, skipping")
|
||||
return
|
||||
p2_puzzle = puzzle_for_pk(derivation_record.pubkey)
|
||||
if uncurried_nft.supports_did:
|
||||
inner_puzzle = nft_puzzles.recurry_nft_puzzle(uncurried_nft, coin_spend.solution.to_program(), p2_puzzle)
|
||||
@@ -301,11 +293,6 @@ class NFTWallet:
|
||||
self.wallet_state_manager.state_changed("nft_coin_removed", self.wallet_info.id)
|
||||
return
|
||||
|
||||
def puzzle_for_pk(self, pk: G1Element) -> Program:
|
||||
inner_puzzle = self.standard_wallet.puzzle_for_pk(bytes(pk))
|
||||
provenance_puzzle = Program.to([NFT_STATE_LAYER_MOD_HASH, inner_puzzle])
|
||||
return provenance_puzzle
|
||||
|
||||
async def get_did_approval_info(
|
||||
self,
|
||||
nft_id: bytes32,
|
||||
|
||||
@@ -268,9 +268,13 @@ class WalletStateManager:
|
||||
|
||||
for wallet_id in targets:
|
||||
target_wallet = self.wallets[wallet_id]
|
||||
|
||||
if not hasattr(target_wallet, "puzzle_for_pk"):
|
||||
self.log.debug("Skipping wallet %s as no derivation paths required", wallet_id)
|
||||
continue
|
||||
last: Optional[uint32] = await self.puzzle_store.get_last_derivation_path_for_wallet(wallet_id)
|
||||
|
||||
self.log.debug(
|
||||
"Fetched last record for wallet %r: %s (from_zero=%r, unused=%r)", wallet_id, last, from_zero, unused
|
||||
)
|
||||
start_index = 0
|
||||
derivation_paths: List[DerivationRecord] = []
|
||||
|
||||
@@ -330,6 +334,7 @@ class WalletStateManager:
|
||||
[record.wallet_id for record in derivation_paths],
|
||||
in_transaction,
|
||||
)
|
||||
|
||||
if unused > 0:
|
||||
await self.puzzle_store.set_used_up_to(uint32(unused - 1), in_transaction)
|
||||
|
||||
@@ -703,6 +708,14 @@ class WalletStateManager:
|
||||
self.log.warning(f"Could not find the launch coin with ID: {launch_id}")
|
||||
return None, None
|
||||
launch_coin: CoinState = response[0]
|
||||
origin_coin = launch_coin.coin
|
||||
|
||||
for wallet in self.wallets.values():
|
||||
if (
|
||||
wallet.type() == WalletType.DECENTRALIZED_ID
|
||||
and origin_coin.name() == wallet.did_info.origin_coin.name()
|
||||
):
|
||||
return wallet.id(), wallet.type()
|
||||
did_wallet = await DIDWallet.create_new_did_wallet_from_coin_spend(
|
||||
self,
|
||||
self.main_wallet,
|
||||
|
||||
Reference in New Issue
Block a user