Skip to content

Commit

Permalink
hint chia.pools and remove from exclusions (#16493)
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky authored Oct 3, 2023
1 parent 4e81bfe commit 0606c23
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
13 changes: 9 additions & 4 deletions chia/pools/pool_puzzles.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_delayed_puz_info_from_launcher_spend(coinsol: CoinSpend) -> Tuple[uint64
######################################


def get_template_singleton_inner_puzzle(inner_puzzle: Program):
def get_template_singleton_inner_puzzle(inner_puzzle: Program) -> Program:
r = inner_puzzle.uncurry()
if r is None:
return False
Expand Down Expand Up @@ -309,7 +309,9 @@ def get_pubkey_from_member_inner_puzzle(inner_puzzle: Program) -> G1Element:
return pubkey


def uncurry_pool_member_inner_puzzle(inner_puzzle: Program): # -> Optional[Tuple[Program, Program, Program]]:
def uncurry_pool_member_inner_puzzle(
inner_puzzle: Program,
) -> Tuple[Program, Program, Program, Program, Program, Program]:
"""
Take a puzzle and return `None` if it's not a "pool member" inner puzzle, or
a triple of `mod_hash, relative_lock_height, pubkey` if it is.
Expand Down Expand Up @@ -352,7 +354,10 @@ def get_inner_puzzle_from_puzzle(full_puzzle: Program) -> Optional[Program]:
_, inner_puzzle = list(args.as_iter())
if not is_pool_singleton_inner_puzzle(inner_puzzle):
return None
return inner_puzzle
# ignoring hint error here for:
# https://github.com/Chia-Network/clvm/pull/102
# https://github.com/Chia-Network/clvm/pull/106
return inner_puzzle # type: ignore[no-any-return]


def pool_state_from_extra_data(extra_data: Program) -> Optional[PoolState]:
Expand Down Expand Up @@ -419,7 +424,7 @@ def pool_state_to_inner_puzzle(
delay_time,
delay_ph,
)
if pool_state.state in [LEAVING_POOL, SELF_POOLING]:
if pool_state.state in [LEAVING_POOL.value, SELF_POOLING.value]:
return escaping_inner_puzzle
else:
return create_pooling_inner_puzzle(
Expand Down
27 changes: 17 additions & 10 deletions chia/pools/pool_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from blspy import G1Element, G2Element, PrivateKey
from typing_extensions import final

from chia.clvm.singleton import SINGLETON_LAUNCHER
from chia.pools.pool_config import PoolWalletConfig, load_pool_config, update_pool_config
from chia.pools.pool_puzzles import (
SINGLETON_LAUNCHER,
create_absorb_spend,
create_full_puzzle,
create_pooling_inner_puzzle,
Expand Down Expand Up @@ -42,7 +42,6 @@
from chia.types.blockchain_format.program import Program
from chia.types.blockchain_format.serialized_program import SerializedProgram
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.coin_record import CoinRecord
from chia.types.coin_spend import CoinSpend, compute_additions
from chia.types.spend_bundle import SpendBundle
from chia.util.ints import uint32, uint64, uint128
Expand All @@ -58,6 +57,9 @@
from chia.wallet.wallet_coin_record import WalletCoinRecord
from chia.wallet.wallet_info import WalletInfo

if TYPE_CHECKING:
from chia.wallet.wallet_state_manager import WalletStateManager


@final
@dataclasses.dataclass
Expand All @@ -72,7 +74,7 @@ class PoolWallet:
MAXIMUM_RELATIVE_LOCK_HEIGHT = 1000
DEFAULT_MAX_CLAIM_SPENDS = 100

wallet_state_manager: Any
wallet_state_manager: WalletStateManager
log: logging.Logger
wallet_info: WalletInfo
standard_wallet: Wallet
Expand Down Expand Up @@ -482,15 +484,22 @@ async def get_pool_wallet_index(self) -> uint32:
async def sign(self, coin_spend: CoinSpend) -> SpendBundle:
async def pk_to_sk(pk: G1Element) -> PrivateKey:
s = find_owner_sk([self.wallet_state_manager.private_key], pk)
if s is None:
if s is None: # pragma: no cover
# No pool wallet transactions _should_ hit this, but it can't hurt to have a backstop
return self.wallet_state_manager.get_private_key_for_pubkey(pk) # pragma: no cover
private_key = await self.wallet_state_manager.get_private_key_for_pubkey(pk)
if private_key is None:
raise ValueError(f"No private key for pubkey: {pk}")
return private_key
else:
# Note that pool_wallet_index may be from another wallet than self.wallet_id
owner_sk, pool_wallet_index = s
if owner_sk is None:
if owner_sk is None: # pragma: no cover
# TODO: this code is dead, per hinting at least
# No pool wallet transactions _should_ hit this, but it can't hurt to have a backstop
return self.wallet_state_manager.get_private_key_for_pubkey(pk) # pragma: no cover
private_key = await self.wallet_state_manager.get_private_key_for_pubkey(pk)
if private_key is None:
raise ValueError(f"No private key for pubkey: {pk}")
return private_key
return owner_sk

return await sign_coin_spends(
Expand Down Expand Up @@ -827,9 +836,7 @@ async def claim_pool_rewards(
self.log.info(f"Bad max_spends_in_tx value of {max_spends_in_tx}. Set to {self.DEFAULT_MAX_CLAIM_SPENDS}.")
max_spends_in_tx = self.DEFAULT_MAX_CLAIM_SPENDS

unspent_coin_records: List[CoinRecord] = list(
await self.wallet_state_manager.coin_store.get_unspent_coins_for_wallet(self.wallet_id)
)
unspent_coin_records = await self.wallet_state_manager.coin_store.get_unspent_coins_for_wallet(self.wallet_id)
if len(unspent_coin_records) == 0:
raise ValueError("Nothing to claim, no transactions to p2_singleton_puzzle_hash")
farming_rewards: List[TransactionRecord] = await self.wallet_state_manager.tx_store.get_farming_rewards()
Expand Down
8 changes: 6 additions & 2 deletions chia/pools/pool_wallet_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from dataclasses import dataclass
from enum import IntEnum
from typing import Dict, Optional
from typing import Any, Dict, Optional

from blspy import G1Element

Expand Down Expand Up @@ -63,7 +63,11 @@ class PoolState(Streamable):
relative_lock_height: uint32


def initial_pool_state_from_dict(state_dict: Dict, owner_pubkey: G1Element, owner_puzzle_hash: bytes32) -> PoolState:
def initial_pool_state_from_dict(
state_dict: Dict[str, Any],
owner_pubkey: G1Element,
owner_puzzle_hash: bytes32,
) -> PoolState:
state_str = state_dict["state"]
singleton_state: PoolSingletonState = PoolSingletonState[state_str]

Expand Down
3 changes: 0 additions & 3 deletions mypy-exclusions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ chia.plotters.plotters
chia.plotters.plotters_util
chia.plotting.manager
chia.plotting.util
chia.pools.pool_puzzles
chia.pools.pool_wallet
chia.pools.pool_wallet_info
chia.rpc.rpc_client
chia.rpc.util
chia.rpc.wallet_rpc_client
Expand Down
4 changes: 2 additions & 2 deletions tests/pools/test_pool_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def mock_get_current_state(self: Any) -> Any:

# Create an empty PoolWallet and populate only the required fields
wallet = PoolWallet(
wallet_state_manager=MockWalletStateManager(),
wallet_state_manager=MockWalletStateManager(), # type: ignore[arg-type]
standard_wallet=cast(Any, MockStandardWallet(canned_puzzlehash=payout_instructions_ph)),
log=MagicMock(),
wallet_info=MagicMock(),
Expand Down Expand Up @@ -180,7 +180,7 @@ async def mock_get_current_state(self: Any) -> Any:

# Create an empty PoolWallet and populate only the required fields
wallet = PoolWallet(
wallet_state_manager=MockWalletStateManager(),
wallet_state_manager=MockWalletStateManager(), # type: ignore[arg-type]
standard_wallet=cast(Any, MockStandardWallet(canned_puzzlehash=payout_instructions_ph)),
log=MagicMock(),
wallet_info=MagicMock(),
Expand Down

0 comments on commit 0606c23

Please sign in to comment.