Skip to content

Commit 15a4536

Browse files
authored
The chia.consensus module no longer depends upon chia.wallet. (#19665)
<!-- Merging Requirements: - Please give your PR a title that is release-note friendly - In order to be merged, you must add the most appropriate category Label (Added, Changed, Fixed) to your PR --> <!-- Explain why this is an improvement (Does this add missing functionality, improve performance, or reduce complexity?) --> ### Purpose: This PR removes a dependency that is inappropriate and caused a dependency loop.
1 parent 28ca7dc commit 15a4536

File tree

10 files changed

+28
-34
lines changed

10 files changed

+28
-34
lines changed

chia/_tests/core/test_farmer_harvester_rpc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from chia._tests.util.misc import assert_rpc_error
2222
from chia._tests.util.rpc import validate_get_routes
2323
from chia._tests.util.time_out_assert import time_out_assert, time_out_assert_custom_interval
24-
from chia.consensus.coinbase import create_puzzlehash_for_pk
2524
from chia.farmer.farmer import Farmer
2625
from chia.plot_sync.receiver import Receiver, get_list_or_len
2726
from chia.plotting.util import add_plot_directory
@@ -40,6 +39,7 @@
4039
from chia.util.config import load_config, lock_and_load_config, save_config
4140
from chia.util.hash import std_hash
4241
from chia.wallet.derive_keys import master_sk_to_wallet_sk, master_sk_to_wallet_sk_unhardened
42+
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_hash_for_pk
4343

4444
log = logging.getLogger(__name__)
4545

@@ -150,8 +150,8 @@ async def test_farmer_reward_target_endpoints(harvester_farmer_environment: Harv
150150
targets_2 = await farmer_rpc_client.get_reward_targets(True, 2)
151151
assert targets_2["have_pool_sk"] and targets_2["have_farmer_sk"]
152152

153-
new_ph: bytes32 = create_puzzlehash_for_pk(master_sk_to_wallet_sk(bt.farmer_master_sk, uint32(2)).get_g1())
154-
new_ph_2: bytes32 = create_puzzlehash_for_pk(master_sk_to_wallet_sk(bt.pool_master_sk, uint32(7)).get_g1())
153+
new_ph: bytes32 = puzzle_hash_for_pk(master_sk_to_wallet_sk(bt.farmer_master_sk, uint32(2)).get_g1())
154+
new_ph_2: bytes32 = puzzle_hash_for_pk(master_sk_to_wallet_sk(bt.pool_master_sk, uint32(7)).get_g1())
155155

156156
await farmer_rpc_client.set_reward_targets(encode_puzzle_hash(new_ph, "xch"), encode_puzzle_hash(new_ph_2, "xch"))
157157
targets_3 = await farmer_rpc_client.get_reward_targets(True, 10)
@@ -164,10 +164,10 @@ async def test_farmer_reward_target_endpoints(harvester_farmer_environment: Harv
164164
assert not targets_4["have_pool_sk"] and targets_4["have_farmer_sk"]
165165

166166
# check observer addresses
167-
observer_farmer: bytes32 = create_puzzlehash_for_pk(
167+
observer_farmer: bytes32 = puzzle_hash_for_pk(
168168
master_sk_to_wallet_sk_unhardened(bt.farmer_master_sk, uint32(2)).get_g1()
169169
)
170-
observer_pool: bytes32 = create_puzzlehash_for_pk(
170+
observer_pool: bytes32 = puzzle_hash_for_pk(
171171
master_sk_to_wallet_sk_unhardened(bt.pool_master_sk, uint32(7)).get_g1()
172172
)
173173
await farmer_rpc_client.set_reward_targets(

chia/_tests/wallet/rpc/test_wallet_rpc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
from chia.cmds.coins import CombineCMD, SplitCMD
5050
from chia.cmds.param_types import CliAmount
5151
from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward
52-
from chia.consensus.coinbase import create_puzzlehash_for_pk
5352
from chia.rpc.full_node_rpc_client import FullNodeRpcClient
5453
from chia.rpc.rpc_client import ResponseFailureError
5554
from chia.rpc.wallet_request_types import (
@@ -102,6 +101,7 @@
102101
from chia.wallet.did_wallet.did_wallet import DIDWallet
103102
from chia.wallet.nft_wallet.nft_wallet import NFTWallet
104103
from chia.wallet.puzzles.clawback.metadata import AutoClaimSettings
104+
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_hash_for_pk
105105
from chia.wallet.signer_protocol import UnsignedTransaction
106106
from chia.wallet.trade_record import TradeRecord
107107
from chia.wallet.trading.offer import Offer
@@ -1702,11 +1702,11 @@ async def _check_delete_key(
17021702

17031703
sk = await wallet_node.get_key_for_fingerprint(farmer_fp, private=True)
17041704
assert sk is not None
1705-
farmer_ph = create_puzzlehash_for_pk(create_sk(sk, uint32(0)).get_g1())
1705+
farmer_ph = puzzle_hash_for_pk(create_sk(sk, uint32(0)).get_g1())
17061706

17071707
sk = await wallet_node.get_key_for_fingerprint(pool_fp, private=True)
17081708
assert sk is not None
1709-
pool_ph = create_puzzlehash_for_pk(create_sk(sk, uint32(0)).get_g1())
1709+
pool_ph = puzzle_hash_for_pk(create_sk(sk, uint32(0)).get_g1())
17101710

17111711
with lock_and_load_config(wallet_node.root_path, "config.yaml") as test_config:
17121712
test_config["farmer"]["xch_target_address"] = encode_puzzle_hash(farmer_ph, "txch")

chia/cmds/init_funcs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import yaml
1010

1111
from chia.cmds.configure import configure
12-
from chia.consensus.coinbase import create_puzzlehash_for_pk
1312
from chia.ssl.create_ssl import create_all_ssl
1413
from chia.ssl.ssl_check import (
1514
DEFAULT_PERMISSIONS_CERT_FILE,
@@ -38,6 +37,7 @@
3837
master_sk_to_wallet_sk_intermediate,
3938
master_sk_to_wallet_sk_unhardened_intermediate,
4039
)
40+
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_hash_for_pk
4141

4242

4343
def dict_add_new_default(updated: dict[str, Any], default: dict[str, Any], do_not_migrate_keys: dict[str, Any]) -> None:
@@ -94,11 +94,11 @@ def check_keys(new_root: Path, keychain: Optional[Keychain] = None) -> None:
9494

9595
all_targets.append(
9696
encode_puzzle_hash(
97-
create_puzzlehash_for_pk(_derive_path_unhardened(intermediate_o, [i]).get_g1()), prefix
97+
puzzle_hash_for_pk(_derive_path_unhardened(intermediate_o, [i]).get_g1()), prefix
9898
)
9999
)
100100
all_targets.append(
101-
encode_puzzle_hash(create_puzzlehash_for_pk(_derive_path(intermediate_n, [i]).get_g1()), prefix)
101+
encode_puzzle_hash(puzzle_hash_for_pk(_derive_path(intermediate_n, [i]).get_g1()), prefix)
102102
)
103103
if all_targets[-1] == config["farmer"].get("xch_target_address") or all_targets[-2] == config[
104104
"farmer"

chia/cmds/keys_funcs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey
1111
from chia_rs.sized_ints import uint32
1212

13-
from chia.consensus.coinbase import create_puzzlehash_for_pk
1413
from chia.types.signing_mode import SigningMode
1514
from chia.util.bech32m import bech32_encode, convertbits, encode_puzzle_hash
1615
from chia.util.config import load_config
@@ -31,6 +30,7 @@
3130
master_sk_to_pool_sk,
3231
master_sk_to_wallet_sk,
3332
)
33+
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_hash_for_pk
3434

3535

3636
def unlock_keyring() -> None:
@@ -197,7 +197,7 @@ def process_key_data(key_data: KeyData) -> dict[str, Any]:
197197
first_wallet_pk = master_pk_to_wallet_pk_unhardened(key_data.public_key, uint32(0))
198198

199199
if first_wallet_pk is not None:
200-
wallet_address: str = encode_puzzle_hash(create_puzzlehash_for_pk(first_wallet_pk), prefix)
200+
wallet_address: str = encode_puzzle_hash(puzzle_hash_for_pk(first_wallet_pk), prefix)
201201
key["wallet_address"] = wallet_address
202202
else:
203203
key["wallet_address"] = None
@@ -423,7 +423,7 @@ class DerivedSearchResultType(Enum):
423423
# Generate a wallet address using the standard p2_delegated_puzzle_or_hidden_puzzle puzzle
424424
assert child_pk is not None
425425
# TODO: consider generating addresses using other puzzles
426-
address = encode_puzzle_hash(create_puzzlehash_for_pk(child_pk), prefix)
426+
address = encode_puzzle_hash(puzzle_hash_for_pk(child_pk), prefix)
427427

428428
for term in remaining_search_terms:
429429
found_item: Any = None
@@ -682,7 +682,7 @@ def derive_wallet_address(
682682
pubkey = master_pk_to_wallet_pk_unhardened(pk, uint32(i))
683683
# Generate a wallet address using the standard p2_delegated_puzzle_or_hidden_puzzle puzzle
684684
# TODO: consider generating addresses using other puzzles
685-
address = encode_puzzle_hash(create_puzzlehash_for_pk(pubkey), prefix)
685+
address = encode_puzzle_hash(puzzle_hash_for_pk(pubkey), prefix)
686686
if show_hd_path:
687687
print(
688688
f"Wallet address {i} "

chia/cmds/sim_funcs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from chia.cmds.cmds_util import get_any_service_client
1616
from chia.cmds.start_funcs import async_start
17-
from chia.consensus.coinbase import create_puzzlehash_for_pk
1817
from chia.protocols.outbound_message import NodeType
1918
from chia.server.resolve_peer_info import set_peer_info
2019
from chia.simulator.simulator_full_node_rpc_client import SimulatorFullNodeRpcClient
@@ -29,6 +28,7 @@
2928
master_sk_to_wallet_sk,
3029
master_sk_to_wallet_sk_unhardened,
3130
)
31+
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_hash_for_pk
3232

3333

3434
def get_ph_from_fingerprint(fingerprint: int, key_id: int = 1) -> bytes32:
@@ -37,7 +37,7 @@ def get_ph_from_fingerprint(fingerprint: int, key_id: int = 1) -> bytes32:
3737
raise Exception("Fingerprint not found")
3838
private_key = priv_key_and_entropy[0]
3939
sk_for_wallet_id: PrivateKey = master_sk_to_wallet_sk(private_key, uint32(key_id))
40-
puzzle_hash: bytes32 = create_puzzlehash_for_pk(sk_for_wallet_id.get_g1())
40+
puzzle_hash: bytes32 = puzzle_hash_for_pk(sk_for_wallet_id.get_g1())
4141
return puzzle_hash
4242

4343

@@ -154,7 +154,7 @@ def display_key_info(fingerprint: int, prefix: str) -> None:
154154
print("Farmer public key (m/12381/8444/0/0):", master_sk_to_farmer_sk(sk).get_g1())
155155
print("Pool public key (m/12381/8444/1/0):", master_sk_to_pool_sk(sk).get_g1())
156156
first_wallet_sk: PrivateKey = master_sk_to_wallet_sk_unhardened(sk, uint32(0))
157-
wallet_address: str = encode_puzzle_hash(create_puzzlehash_for_pk(first_wallet_sk.get_g1()), prefix)
157+
wallet_address: str = encode_puzzle_hash(puzzle_hash_for_pk(first_wallet_sk.get_g1()), prefix)
158158
print(f"First wallet address: {wallet_address}")
159159
assert seed is not None
160160
print("Master private key (m):", bytes(sk).hex())

chia/consensus/coinbase.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
from __future__ import annotations
22

3-
from chia_rs import G1Element
43
from chia_rs.sized_bytes import bytes32
54
from chia_rs.sized_ints import uint32, uint64
65

76
from chia.types.blockchain_format.coin import Coin
8-
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_hash_for_pk
9-
10-
11-
def create_puzzlehash_for_pk(pub_key: G1Element) -> bytes32:
12-
return puzzle_hash_for_pk(pub_key)
137

148

159
def pool_parent_id(block_height: uint32, genesis_challenge: bytes32) -> bytes32:

chia/daemon/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from chia import __version__
2828
from chia.cmds.init_funcs import check_keys, chia_init
2929
from chia.cmds.passphrase_funcs import default_passphrase, using_default_passphrase
30-
from chia.consensus.coinbase import create_puzzlehash_for_pk
3130
from chia.daemon.keychain_server import KeychainServer, keychain_commands
3231
from chia.daemon.windows_signal import kill
3332
from chia.plotters.plotters import get_available_plotters
@@ -55,6 +54,7 @@
5554
master_sk_to_pool_sk,
5655
master_sk_to_wallet_sk,
5756
)
57+
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_hash_for_pk
5858

5959
io_pool_exc = ThreadPoolExecutor()
6060

@@ -669,7 +669,7 @@ async def get_wallet_addresses(self, websocket: WebSocketResponse, request: dict
669669
pk = sk.get_g1()
670670
else:
671671
pk = master_pk_to_wallet_pk_unhardened(key.public_key, uint32(i))
672-
wallet_address = encode_puzzle_hash(create_puzzlehash_for_pk(pk), prefix)
672+
wallet_address = encode_puzzle_hash(puzzle_hash_for_pk(pk), prefix)
673673
if non_observer_derivation:
674674
hd_path = f"m/12381n/8444n/2n/{i}n"
675675
else:

chia/simulator/block_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
from chia.consensus.block_creation import create_unfinished_block, unfinished_block_to_full_block
4545
from chia.consensus.block_record import BlockRecordProtocol
4646
from chia.consensus.blockchain_interface import BlockRecordsProtocol
47-
from chia.consensus.coinbase import create_puzzlehash_for_pk
4847
from chia.consensus.condition_costs import ConditionCost
4948
from chia.consensus.constants import replace_str_to_bytes
5049
from chia.consensus.default_constants import DEFAULT_CONSTANTS
@@ -120,6 +119,7 @@
120119
master_sk_to_pool_sk,
121120
master_sk_to_wallet_sk,
122121
)
122+
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_hash_for_pk
123123

124124
DESERIALIZE_MOD = Program.from_bytes(CHIALISP_DESERIALISATION)
125125

@@ -446,10 +446,10 @@ async def setup_keys(self, fingerprint: Optional[int] = None, reward_ph: Optiona
446446
self.pool_pk = master_sk_to_pool_sk(self.pool_master_sk).get_g1()
447447

448448
if reward_ph is None:
449-
self.farmer_ph: bytes32 = create_puzzlehash_for_pk(
449+
self.farmer_ph: bytes32 = puzzle_hash_for_pk(
450450
master_sk_to_wallet_sk(self.farmer_master_sk, uint32(0)).get_g1()
451451
)
452-
self.pool_ph: bytes32 = create_puzzlehash_for_pk(
452+
self.pool_ph: bytes32 = puzzle_hash_for_pk(
453453
master_sk_to_wallet_sk(self.pool_master_sk, uint32(0)).get_g1()
454454
)
455455
else:

chia/simulator/simulator_test_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from chia_rs.sized_bytes import bytes32
1010
from chia_rs.sized_ints import uint32
1111

12-
from chia.consensus.coinbase import create_puzzlehash_for_pk
1312
from chia.daemon.server import WebSocketServer, daemon_launch_lock_path
1413
from chia.server.signal_handlers import SignalHandlers
1514
from chia.simulator.full_node_simulator import FullNodeSimulator
@@ -29,6 +28,7 @@
2928
from chia.util.keychain import Keychain
3029
from chia.util.lock import Lockfile
3130
from chia.wallet.derive_keys import master_sk_to_wallet_sk
31+
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_hash_for_pk
3232

3333
"""
3434
These functions are used to test the simulator.
@@ -56,7 +56,7 @@ def get_puzzle_hash_from_key(keychain: Keychain, fingerprint: int, key_id: int =
5656
raise Exception("Fingerprint not found")
5757
private_key = priv_key_and_entropy[0]
5858
sk_for_wallet_id: PrivateKey = master_sk_to_wallet_sk(private_key, uint32(key_id))
59-
puzzle_hash: bytes32 = create_puzzlehash_for_pk(sk_for_wallet_id.get_g1())
59+
puzzle_hash: bytes32 = puzzle_hash_for_pk(sk_for_wallet_id.get_g1())
6060
return puzzle_hash
6161

6262

chia/wallet/derive_keys.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from chia_rs.sized_bytes import bytes32
77
from chia_rs.sized_ints import uint32
88

9-
from chia.consensus.coinbase import create_puzzlehash_for_pk
9+
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_hash_for_pk
1010

1111
# EIP 2334 bls key derivation
1212
# https://eips.ethereum.org/EIPS/eip-2334
@@ -131,8 +131,8 @@ def match_address_to_sk(
131131

132132
for i in range(max_ph_to_search):
133133
phs = [
134-
create_puzzlehash_for_pk(master_sk_to_wallet_sk(sk, uint32(i)).get_g1()),
135-
create_puzzlehash_for_pk(master_sk_to_wallet_sk_unhardened(sk, uint32(i)).get_g1()),
134+
puzzle_hash_for_pk(master_sk_to_wallet_sk(sk, uint32(i)).get_g1()),
135+
puzzle_hash_for_pk(master_sk_to_wallet_sk_unhardened(sk, uint32(i)).get_g1()),
136136
]
137137

138138
for address in search_list:

0 commit comments

Comments
 (0)