Skip to content

Commit 8bb8a1b

Browse files
authored
Migrate puzzles away from load_clvm to import from chia_puzzles_py (#19055)
* add dependency for chia_puzzles_py * migrate cat and dao wallets to new repo * migrate did wallet * more migration and deduplication * change singleton launcher hash import in rpc * stop importing singleton launcher from nft_puzzles in nft_wallet * remove SINGLETON_LAUNCHER_PUZZLE import from nft_puzzles * remove unused import * ruff check and fix * use graftroot dl offers from chia_puzzles_py * get rid of more non explicit exports * remove circular dependency * ruff check * migrate py files in puzzles to use chia_puzzles_py * fix import * fix more imports * migrate clawback wallet and fix typo (requires version update of chia_puzzles_py) * delete puzzles and separate nft puzzles from puzzle_utils * use 0.19.1 version of chia_puzzles_py * more nft puzzle detangling * use latest chia_puzzles_py and migrate pools * ruff fixes * delete pool puzzles folder * remove load_clvm from test_singleton and test_singleton_lifecycle_fast * mypy fixes * ruff fixes * remove manage_clvm check precommit hook * update version * update chia_puzzles dependency to 0.19.4 * remove full_node puzzles * remove test for condition codes * change generator type to SerializedProgram * remove remaining load_clvms that can be factored out * delete consensus puzzles * fix test_singleton_lifecycle_fast * cast debug_spend_bundle coin name to bytes32 * ruff debug_spend_bundle * update chia-puzzles and fix typo * fix line endings * fix typo in ROM_BOOTSTRAP_GENERATOR references * remove bytes32 cast from debug_spend_bundle * update chia-puzzles-py dependency to version 0.20.1 and refactor ACS_TRANSFER_PROGRAM initialization * remove unused puzzle files * singleton_top_layer exports hashs now which are imported from chia_puzzles * remove .get_tree_hash() in favor of importing the hash * remaining hash imports * regenerate poetry.lock and pyproject.toml from main * import singleton launcher hash from explicit export * import SINGLETON_LAUNCHER_HASH from chia.wallet.singleton in test_pool_rpc.py * import SINGLETON_MOD_HASH from chia.wallet.puzzles.singleton_top_layer in test_pool_puzzles_lifecycle.py * poetry lock --no-update post-rebase * re-regenerate lock file --no-update * fix rebased block_tools
1 parent 27c34ec commit 8bb8a1b

File tree

188 files changed

+858
-5320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+858
-5320
lines changed

.pre-commit-config.yaml

-7
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ repos:
5757
- id: check-merge-conflict
5858
- id: check-ast
5959
- id: debug-statements
60-
- repo: local
61-
hooks:
62-
- id: clvm_hex
63-
name: .clsp.hex files
64-
entry: ./activated.py python tools/manage_clvm.py check
65-
language: system
66-
pass_filenames: false
6760
- repo: local
6861
hooks:
6962
- id: chialispp

chia/_tests/clvm/test_chialisp_deserialization.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import annotations
22

33
import pytest
4+
from chia_puzzles_py.programs import CHIALISP_DESERIALISATION
45

56
from chia.types.blockchain_format.program import INFINITE_COST, Program
67
from chia.util.byte_types import hexstr_to_bytes
7-
from chia.wallet.puzzles.load_clvm import load_clvm
88

9-
DESERIALIZE_MOD = load_clvm("chialisp_deserialisation.clsp", package_or_requirement="chia.consensus.puzzles")
9+
DESERIALIZE_MOD = Program.from_bytes(CHIALISP_DESERIALISATION)
1010

1111

1212
def serialized_atom_overflow(size):

chia/_tests/clvm/test_condition_codes.py

-13
This file was deleted.

chia/_tests/generator/test_compression.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
import io
55
from typing import Any
66

7+
from chia_puzzles_py.programs import (
8+
BLOCK_PROGRAM_ZERO,
9+
CHIALISP_DESERIALISATION,
10+
DECOMPRESS_COIN_SPEND_ENTRY,
11+
DECOMPRESS_COIN_SPEND_ENTRY_WITH_PREFIX,
12+
DECOMPRESS_PUZZLE,
13+
ROM_BOOTSTRAP_GENERATOR,
14+
)
715
from chia_rs import serialized_length
816
from clvm.serialize import sexp_from_stream
917
from clvm.SExp import SExp
@@ -15,18 +23,20 @@
1523
from chia.util.ints import uint32
1624
from chia.wallet.puzzles.load_clvm import load_clvm
1725

18-
TEST_GEN_DESERIALIZE = load_clvm(
19-
"test_generator_deserialize.clsp", package_or_requirement="chia._tests.generator.puzzles"
20-
)
21-
DESERIALIZE_MOD = load_clvm("chialisp_deserialisation.clsp", package_or_requirement="chia.consensus.puzzles")
26+
DESERIALIZE_MOD = Program.from_bytes(CHIALISP_DESERIALISATION)
27+
28+
GENERATOR_MOD: Program = Program.from_bytes(ROM_BOOTSTRAP_GENERATOR)
2229

23-
DECOMPRESS_PUZZLE = load_clvm("decompress_puzzle.clsp", package_or_requirement="chia.full_node.puzzles")
24-
DECOMPRESS_CSE = load_clvm("decompress_coin_spend_entry.clsp", package_or_requirement="chia.full_node.puzzles")
2530

26-
DECOMPRESS_CSE_WITH_PREFIX = load_clvm(
27-
"decompress_coin_spend_entry_with_prefix.clsp", package_or_requirement="chia.full_node.puzzles"
31+
DECOMPRESS_PUZZLE = Program.from_bytes(DECOMPRESS_PUZZLE)
32+
DECOMPRESS_CSE = Program.from_bytes(DECOMPRESS_COIN_SPEND_ENTRY)
33+
34+
DECOMPRESS_CSE_WITH_PREFIX = Program.from_bytes(DECOMPRESS_COIN_SPEND_ENTRY_WITH_PREFIX)
35+
DECOMPRESS_BLOCK = Program.from_bytes(BLOCK_PROGRAM_ZERO)
36+
37+
TEST_GEN_DESERIALIZE = load_clvm(
38+
"test_generator_deserialize.clsp", package_or_requirement="chia._tests.generator.puzzles"
2839
)
29-
DECOMPRESS_BLOCK = load_clvm("block_program_zero.clsp", package_or_requirement="chia.full_node.puzzles")
3040
TEST_MULTIPLE = load_clvm(
3141
"test_multiple_generator_input_arguments.clsp", package_or_requirement="chia._tests.generator.puzzles"
3242
)

chia/_tests/generator/test_rom.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from chia_puzzles_py.programs import CHIALISP_DESERIALISATION, ROM_BOOTSTRAP_GENERATOR
34
from clvm.CLVMObject import CLVMStorage
45
from clvm_tools import binutils
56
from clvm_tools.clvmc import compile_clvm_text
@@ -13,16 +14,13 @@
1314
from chia.types.generator_types import BlockGenerator
1415
from chia.types.spend_bundle_conditions import SpendConditions
1516
from chia.util.ints import uint32
16-
from chia.wallet.puzzles.load_clvm import load_clvm, load_serialized_clvm_maybe_recompile
1717

18-
MAX_COST = 10**15
19-
COST_PER_BYTE = 12000
18+
DESERIALIZE_MOD = Program.from_bytes(CHIALISP_DESERIALISATION)
2019

20+
GENERATOR_MOD: SerializedProgram = SerializedProgram.from_bytes(ROM_BOOTSTRAP_GENERATOR)
2121

22-
DESERIALIZE_MOD = load_clvm("chialisp_deserialisation.clsp", package_or_requirement="chia.consensus.puzzles")
23-
GENERATOR_MOD: SerializedProgram = load_serialized_clvm_maybe_recompile(
24-
"rom_bootstrap_generator.clsp", package_or_requirement="chia.consensus.puzzles"
25-
)
22+
MAX_COST = 10**15
23+
COST_PER_BYTE = 12000
2624

2725

2826
GENERATOR_CODE = """

chia/_tests/pools/test_pool_puzzles_lifecycle.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from chia._tests.util.key_tool import KeyTool
1212
from chia.consensus.default_constants import DEFAULT_CONSTANTS
1313
from chia.pools.pool_puzzles import (
14-
SINGLETON_MOD_HASH,
1514
create_absorb_spend,
1615
create_p2_singleton_puzzle,
1716
create_p2_singleton_puzzle_hash,
@@ -41,6 +40,7 @@
4140
puzzle_for_pk,
4241
solution_for_conditions,
4342
)
43+
from chia.wallet.puzzles.singleton_top_layer import SINGLETON_MOD_HASH
4444
from chia.wallet.singleton import get_most_recent_singleton_coin_from_coin_spend
4545

4646
"""

chia/_tests/pools/test_pool_rpc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from chia._tests.util.setup_nodes import setup_simulators_and_wallets_service
2121
from chia._tests.util.time_out_assert import time_out_assert
2222
from chia.consensus.constants import ConsensusConstants
23-
from chia.pools.pool_puzzles import SINGLETON_LAUNCHER_HASH
2423
from chia.pools.pool_wallet_info import PoolSingletonState, PoolWalletInfo
2524
from chia.rpc.wallet_rpc_client import WalletRpcClient
2625
from chia.simulator.add_blocks_in_batches import add_blocks_in_batches
@@ -36,6 +35,7 @@
3635
from chia.util.config import load_config
3736
from chia.util.ints import uint32, uint64
3837
from chia.wallet.derive_keys import find_authentication_sk, find_owner_sk
38+
from chia.wallet.singleton import SINGLETON_LAUNCHER_PUZZLE_HASH as SINGLETON_LAUNCHER_HASH
3939
from chia.wallet.transaction_record import TransactionRecord
4040
from chia.wallet.util.transaction_type import TransactionType
4141
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG

chia/_tests/util/run_block.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@
55
from pathlib import Path
66
from typing import Any
77

8+
from chia_puzzles_py.programs import CHIALISP_DESERIALISATION
89
from chia_rs import Coin
910

1011
from chia.consensus.constants import ConsensusConstants
12+
from chia.types.blockchain_format.program import Program
1113
from chia.types.blockchain_format.serialized_program import SerializedProgram
1214
from chia.types.blockchain_format.sized_bytes import bytes32
1315
from chia.types.condition_opcodes import ConditionOpcode
1416
from chia.types.condition_with_args import ConditionWithArgs
1517
from chia.types.generator_types import BlockGenerator
1618
from chia.util.ints import uint32, uint64
1719
from chia.wallet.cat_wallet.cat_utils import match_cat_puzzle
18-
from chia.wallet.puzzles.load_clvm import load_serialized_clvm_maybe_recompile
1920
from chia.wallet.uncurried_puzzle import uncurry_puzzle
2021

21-
DESERIALIZE_MOD = load_serialized_clvm_maybe_recompile(
22-
"chialisp_deserialisation.clsp", package_or_requirement="chia.consensus.puzzles"
23-
)
22+
DESERIALIZE_MOD = Program.from_bytes(CHIALISP_DESERIALISATION)
2423

2524

2625
@dataclass

chia/_tests/wallet/dao_wallet/test_dao_clvm.py

+29-43
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,35 @@
1717
from chia.util.errors import Err
1818
from chia.util.hash import std_hash
1919
from chia.util.ints import uint32, uint64
20-
from chia.wallet.cat_wallet.cat_utils import CAT_MOD
20+
from chia.wallet.cat_wallet.cat_utils import CAT_MOD, CAT_MOD_HASH
2121
from chia.wallet.dao_wallet.dao_info import DAORules
22-
from chia.wallet.dao_wallet.dao_utils import curry_singleton, get_p2_singleton_puzhash, get_treasury_puzzle
23-
from chia.wallet.puzzles.load_clvm import load_clvm
22+
from chia.wallet.dao_wallet.dao_utils import (
23+
DAO_FINISHED_STATE,
24+
DAO_FINISHED_STATE_HASH,
25+
DAO_LOCKUP_MOD,
26+
DAO_PROPOSAL_MOD,
27+
DAO_PROPOSAL_TIMER_MOD,
28+
DAO_PROPOSAL_TIMER_MOD_HASH,
29+
DAO_PROPOSAL_VALIDATOR_MOD,
30+
DAO_PROPOSAL_VALIDATOR_MOD_HASH,
31+
DAO_TREASURY_MOD,
32+
DAO_TREASURY_MOD_HASH,
33+
P2_SINGLETON_AGGREGATOR_MOD,
34+
P2_SINGLETON_MOD,
35+
SPEND_P2_SINGLETON_MOD,
36+
curry_singleton,
37+
get_p2_singleton_puzhash,
38+
get_treasury_puzzle,
39+
)
40+
from chia.wallet.dao_wallet.dao_utils import (
41+
DAO_UPDATE_PROPOSAL_MOD as DAO_UPDATE_MOD,
42+
)
43+
from chia.wallet.singleton import SINGLETON_LAUNCHER_PUZZLE_HASH as SINGLETON_LAUNCHER_HASH
44+
from chia.wallet.singleton import SINGLETON_TOP_LAYER_MOD as SINGLETON_MOD
45+
from chia.wallet.singleton import SINGLETON_TOP_LAYER_MOD_HASH as SINGLETON_MOD_HASH
2446
from chia.wallet.singleton import create_singleton_puzzle_hash
2547
from chia.wallet.wallet_spend_bundle import WalletSpendBundle
2648

27-
CAT_MOD_HASH: bytes32 = CAT_MOD.get_tree_hash()
28-
SINGLETON_MOD: Program = load_clvm("singleton_top_layer_v1_1.clsp")
29-
SINGLETON_MOD_HASH: bytes32 = SINGLETON_MOD.get_tree_hash()
30-
SINGLETON_LAUNCHER: Program = load_clvm("singleton_launcher.clsp")
31-
SINGLETON_LAUNCHER_HASH: bytes32 = SINGLETON_LAUNCHER.get_tree_hash()
32-
DAO_LOCKUP_MOD: Program = load_clvm("dao_lockup.clsp")
33-
DAO_LOCKUP_MOD_HASH: bytes32 = DAO_LOCKUP_MOD.get_tree_hash()
34-
DAO_PROPOSAL_TIMER_MOD: Program = load_clvm("dao_proposal_timer.clsp")
35-
DAO_PROPOSAL_TIMER_MOD_HASH: bytes32 = DAO_PROPOSAL_TIMER_MOD.get_tree_hash()
36-
DAO_PROPOSAL_MOD: Program = load_clvm("dao_proposal.clsp")
37-
DAO_PROPOSAL_MOD_HASH: bytes32 = DAO_PROPOSAL_MOD.get_tree_hash()
38-
DAO_PROPOSAL_VALIDATOR_MOD: Program = load_clvm("dao_proposal_validator.clsp")
39-
DAO_PROPOSAL_VALIDATOR_MOD_HASH: bytes32 = DAO_PROPOSAL_VALIDATOR_MOD.get_tree_hash()
40-
DAO_TREASURY_MOD: Program = load_clvm("dao_treasury.clsp")
41-
DAO_TREASURY_MOD_HASH: bytes32 = DAO_TREASURY_MOD.get_tree_hash()
42-
SPEND_P2_SINGLETON_MOD: Program = load_clvm("dao_spend_p2_singleton_v2.clsp")
43-
SPEND_P2_SINGLETON_MOD_HASH: bytes32 = SPEND_P2_SINGLETON_MOD.get_tree_hash()
44-
DAO_FINISHED_STATE: Program = load_clvm("dao_finished_state.clsp")
45-
DAO_FINISHED_STATE_HASH: bytes32 = DAO_FINISHED_STATE.get_tree_hash()
46-
DAO_CAT_TAIL: Program = load_clvm(
47-
"genesis_by_coin_id_or_singleton.clsp", package_or_requirement="chia.wallet.cat_wallet.puzzles"
48-
)
49-
DAO_CAT_TAIL_HASH: bytes32 = DAO_CAT_TAIL.get_tree_hash()
50-
P2_SINGLETON_MOD: Program = load_clvm("p2_singleton_via_delegated_puzzle.clsp")
51-
P2_SINGLETON_MOD_HASH: bytes32 = P2_SINGLETON_MOD.get_tree_hash()
52-
P2_SINGLETON_AGGREGATOR_MOD: Program = load_clvm("p2_singleton_aggregator.clsp")
53-
P2_SINGLETON_AGGREGATOR_MOD_HASH: bytes32 = P2_SINGLETON_AGGREGATOR_MOD.get_tree_hash()
54-
DAO_UPDATE_MOD: Program = load_clvm("dao_update_proposal.clsp")
55-
DAO_UPDATE_MOD_HASH: bytes32 = DAO_UPDATE_MOD.get_tree_hash()
56-
5749

5850
def test_finished_state() -> None:
5951
"""
@@ -63,9 +55,7 @@ def test_finished_state() -> None:
6355
the lockup puzzle.
6456
"""
6557
proposal_id = Program.to("proposal_id").get_tree_hash()
66-
singleton_struct: Program = Program.to(
67-
(SINGLETON_MOD.get_tree_hash(), (proposal_id, SINGLETON_LAUNCHER.get_tree_hash()))
68-
)
58+
singleton_struct: Program = Program.to((SINGLETON_MOD_HASH, (proposal_id, SINGLETON_LAUNCHER_HASH)))
6959
finished_inner_puz = DAO_FINISHED_STATE.curry(singleton_struct, DAO_FINISHED_STATE_HASH)
7060
finished_full_puz = SINGLETON_MOD.curry(singleton_struct, finished_inner_puz)
7161
inner_sol = Program.to([1])
@@ -93,9 +83,7 @@ def test_proposal() -> None:
9383
CAT_TAIL_HASH = Program.to("tail").get_tree_hash()
9484
treasury_id = Program.to("treasury").get_tree_hash()
9585
singleton_id = Program.to("singleton_id").get_tree_hash()
96-
singleton_struct: Program = Program.to(
97-
(SINGLETON_MOD.get_tree_hash(), (singleton_id, SINGLETON_LAUNCHER.get_tree_hash()))
98-
)
86+
singleton_struct: Program = Program.to((SINGLETON_MOD_HASH, (singleton_id, SINGLETON_LAUNCHER_HASH)))
9987
self_destruct_time = 1000 # number of blocks
10088
oracle_spend_delay = 10
10189
active_votes_list = [0xFADEDDAB] # are the ids of previously voted on proposals?
@@ -387,9 +375,7 @@ def test_proposal_timer() -> None:
387375
CAT_TAIL_HASH = Program.to("tail").get_tree_hash()
388376
treasury_id = Program.to("treasury").get_tree_hash()
389377
singleton_id = Program.to("singleton_id").get_tree_hash()
390-
singleton_struct: Program = Program.to(
391-
(SINGLETON_MOD.get_tree_hash(), (singleton_id, SINGLETON_LAUNCHER.get_tree_hash()))
392-
)
378+
singleton_struct: Program = Program.to((SINGLETON_MOD_HASH, (singleton_id, SINGLETON_LAUNCHER_HASH)))
393379
dao_lockup_self = DAO_LOCKUP_MOD.curry(
394380
SINGLETON_MOD_HASH,
395381
SINGLETON_LAUNCHER_HASH,
@@ -482,7 +468,7 @@ def test_validator() -> None:
482468

483469
# Setup the proposal
484470
proposal_id = Program.to("proposal_id").get_tree_hash()
485-
proposal_struct: Program = Program.to((SINGLETON_MOD.get_tree_hash(), (proposal_id, SINGLETON_LAUNCHER_HASH)))
471+
proposal_struct: Program = Program.to((SINGLETON_MOD_HASH, (proposal_id, SINGLETON_LAUNCHER_HASH)))
486472
CAT_TAIL_HASH = Program.to("tail").get_tree_hash()
487473
acs: Program = Program.to(1)
488474
acs_ph: bytes32 = acs.get_tree_hash()

chia/_tests/wallet/db_wallet/test_db_graftroot.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
from chia.types.coin_spend import make_spend
1111
from chia.types.mempool_inclusion_status import MempoolInclusionStatus
1212
from chia.util.errors import Err
13-
from chia.wallet.puzzles.load_clvm import load_clvm
13+
from chia.wallet.db_wallet.db_wallet_puzzles import GRAFTROOT_DL_OFFERS
1414
from chia.wallet.util.merkle_utils import build_merkle_tree, build_merkle_tree_from_binary_tree, simplify_merkle_proof
1515
from chia.wallet.wallet_spend_bundle import WalletSpendBundle
1616

17-
GRAFTROOT_MOD = load_clvm("graftroot_dl_offers.clsp", package_or_requirement="chia.data_layer.puzzles")
18-
1917
# Always returns the last value
2018
# (mod solution
2119
#
@@ -46,7 +44,7 @@ async def test_graftroot(cost_logger: CostLogger) -> None:
4644
desired_key_values = ((bytes32.zeros, bytes32([1] * 32)), (bytes32([7] * 32), bytes32([8] * 32)))
4745
desired_row_hashes: list[bytes32] = [build_merkle_tree_from_binary_tree(kv)[0] for kv in desired_key_values]
4846
fake_struct: Program = Program.to((ACS_PH, NIL_PH))
49-
graftroot_puzzle: Program = GRAFTROOT_MOD.curry(
47+
graftroot_puzzle: Program = GRAFTROOT_DL_OFFERS.curry(
5048
# Do everything twice to test depending on multiple singleton updates
5149
p2_conditions,
5250
[fake_struct, fake_struct],

chia/_tests/wallet/nft_wallet/test_nft_lifecycle.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
from chia.types.mempool_inclusion_status import MempoolInclusionStatus
1313
from chia.util.errors import Err
1414
from chia.wallet.conditions import AssertPuzzleAnnouncement
15-
from chia.wallet.nft_wallet.nft_puzzles import (
16-
NFT_METADATA_UPDATER,
17-
NFT_TRANSFER_PROGRAM_DEFAULT,
15+
from chia.wallet.nft_wallet.nft_puzzle_utils import (
1816
construct_ownership_layer,
1917
create_nft_layer_puzzle_with_curry_params,
2018
metadata_to_program,
2119
)
20+
from chia.wallet.nft_wallet.nft_puzzles import NFT_METADATA_UPDATER, NFT_TRANSFER_PROGRAM_DEFAULT
2221
from chia.wallet.wallet_spend_bundle import WalletSpendBundle
2322

2423
ACS = Program.to(1)

0 commit comments

Comments
 (0)