Skip to content

Commit

Permalink
optimize launcher_id_to_p2_puzzle_hash()
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed May 4, 2024
1 parent fdb87e6 commit a3cb749
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions chia/_tests/pools/test_pool_puzzles_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
SINGLETON_MOD_HASH,
create_absorb_spend,
create_p2_singleton_puzzle,
create_p2_singleton_puzzle_hash,
create_pooling_inner_puzzle,
create_travel_spend,
create_waiting_room_inner_puzzle,
Expand Down Expand Up @@ -189,6 +190,12 @@ def test_pool_lifecycle(self):
DELAY_PH,
)
p2_singleton_ph: bytes32 = p2_singleton_puz.get_tree_hash()
assert p2_singleton_ph == create_p2_singleton_puzzle_hash(
SINGLETON_MOD_HASH,
launcher_id,
DELAY_TIME,
DELAY_PH,
)
assert uncurry_pool_waitingroom_inner_puzzle(pool_wr_innerpuz) == (
starting_ph,
relative_lock_height,
Expand Down
24 changes: 21 additions & 3 deletions chia/pools/pool_puzzles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import List, Optional, Tuple

from chia_rs import G1Element
from clvm.casts import int_to_bytes

from chia.clvm.singleton import SINGLETON_LAUNCHER
from chia.consensus.block_rewards import calculate_pool_reward
Expand All @@ -17,6 +18,7 @@
from chia.util.ints import uint32, uint64
from chia.wallet.puzzles.load_clvm import load_clvm_maybe_recompile
from chia.wallet.puzzles.singleton_top_layer import puzzle_for_singleton
from chia.wallet.util.curry_and_treehash import calculate_hash_of_quoted_mod_hash, curry_and_treehash, shatree_atom

log = logging.getLogger(__name__)
# "Full" is the outer singleton, with the inner puzzle filled in
Expand All @@ -31,6 +33,7 @@
POOL_MEMBER_HASH = POOL_MEMBER_MOD.get_tree_hash()
POOL_WAITING_ROOM_HASH = POOL_WAITING_ROOM_MOD.get_tree_hash()
P2_SINGLETON_HASH = P2_SINGLETON_MOD.get_tree_hash()
P2_SINGLETON_HASH_QUOTED = calculate_hash_of_quoted_mod_hash(P2_SINGLETON_HASH)
POOL_OUTER_MOD_HASH = POOL_OUTER_MOD.get_tree_hash()
SINGLETON_LAUNCHER_HASH = SINGLETON_LAUNCHER.get_tree_hash()
SINGLETON_MOD_HASH = POOL_OUTER_MOD_HASH
Expand Down Expand Up @@ -90,10 +93,25 @@ def create_p2_singleton_puzzle(
)


def create_p2_singleton_puzzle_hash(
singleton_mod_hash: bytes,
launcher_id: bytes32,
seconds_delay: uint64,
delayed_puzzle_hash: bytes32,
) -> bytes32:
# curry params are SINGLETON_MOD_HASH LAUNCHER_ID LAUNCHER_PUZZLE_HASH SECONDS_DELAY DELAYED_PUZZLE_HASH
return curry_and_treehash(
P2_SINGLETON_HASH_QUOTED,
shatree_atom(singleton_mod_hash),
shatree_atom(launcher_id),
shatree_atom(SINGLETON_LAUNCHER_HASH),
shatree_atom(int_to_bytes(seconds_delay)),
shatree_atom(delayed_puzzle_hash),
)


def launcher_id_to_p2_puzzle_hash(launcher_id: bytes32, seconds_delay: uint64, delayed_puzzle_hash: bytes32) -> bytes32:
return create_p2_singleton_puzzle(
SINGLETON_MOD_HASH, launcher_id, seconds_delay, delayed_puzzle_hash
).get_tree_hash()
return create_p2_singleton_puzzle_hash(SINGLETON_MOD_HASH, launcher_id, seconds_delay, delayed_puzzle_hash)


def get_delayed_puz_info_from_launcher_spend(coinsol: CoinSpend) -> Tuple[uint64, bytes32]:
Expand Down

0 comments on commit a3cb749

Please sign in to comment.