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 3, 2024
1 parent 1cc6819 commit e375fcb
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions chia/pools/pool_puzzles.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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

log = logging.getLogger(__name__)
# "Full" is the outer singleton, with the inner puzzle filled in
Expand All @@ -31,6 +32,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 +92,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,
Program.to(singleton_mod_hash).get_tree_hash(),
Program.to(launcher_id).get_tree_hash(),
Program.to(SINGLETON_LAUNCHER_HASH).get_tree_hash(),
Program.to(seconds_delay).get_tree_hash(),
Program.to(delayed_puzzle_hash).get_tree_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 e375fcb

Please sign in to comment.