Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some unused imports #287

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pool/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from chia.types.blockchain_format.proof_of_space import verify_and_get_quality_string
from chia.types.coin_record import CoinRecord
from chia.types.coin_spend import CoinSpend
from chia.types.spend_bundle import SpendBundle
from chia.util.bech32m import decode_puzzle_hash
from chia.consensus.constants import ConsensusConstants
from chia.util.ints import uint8, uint16, uint32, uint64
Expand Down
1 change: 0 additions & 1 deletion pool/pool_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def get_ssl_context(config):

class PoolServer:
def __init__(self, config: Dict, constants: ConsensusConstants, pool_store: Optional[AbstractPoolStore] = None):

# We load our configurations from here
with open(os.getcwd() + "/config.yaml") as f:
pool_config: Dict = yaml.safe_load(f)
Expand Down
2 changes: 1 addition & 1 deletion pool/singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from chia.rpc.wallet_rpc_client import WalletRpcClient
from chia.types.announcement import Announcement
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.program import Program, SerializedProgram
from chia.types.blockchain_format.program import Program
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.coin_record import CoinRecord
from chia.types.coin_spend import CoinSpend
Expand Down
24 changes: 11 additions & 13 deletions pool/store/mariadb_store.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import os
import yaml
import logging
from pathlib import Path
from typing import Optional, Set, List, Tuple, Dict

import asyncio
import aiomysql
import pymysql
from blspy import G1Element
Expand Down Expand Up @@ -94,7 +92,7 @@ def _row_to_farmer_record(row) -> FarmerRecord:
)

async def add_farmer_record(self, farmer_record: FarmerRecord, metadata: RequestMetadata):
with (await self.pool) as connection:
with await self.pool as connection:
cursor = await connection.cursor()
await cursor.execute(
f"INSERT INTO farmer VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) "
Expand Down Expand Up @@ -127,7 +125,7 @@ async def add_farmer_record(self, farmer_record: FarmerRecord, metadata: Request

async def get_farmer_record(self, launcher_id: bytes32) -> Optional[FarmerRecord]:
# TODO(pool): use cache
with (await self.pool) as connection:
with await self.pool as connection:
cursor = await connection.cursor()
await cursor.execute(
f"SELECT * FROM farmer WHERE launcher_id=%s",
Expand All @@ -139,7 +137,7 @@ async def get_farmer_record(self, launcher_id: bytes32) -> Optional[FarmerRecord
return self._row_to_farmer_record(row)

async def update_difficulty(self, launcher_id: bytes32, difficulty: uint64):
with (await self.pool) as connection:
with await self.pool as connection:
connection = await self.pool.acquire()
cursor = await connection.cursor()
await cursor.execute(
Expand All @@ -155,7 +153,7 @@ async def update_singleton(
is_pool_member: bool,
):
entry = (bytes(singleton_tip), bytes(singleton_tip_state), int(is_pool_member), launcher_id.hex())
with (await self.pool) as connection:
with await self.pool as connection:
cursor = await connection.cursor()
await cursor.execute(
f"UPDATE farmer SET singleton_tip=%s, singleton_tip_state=%s, is_pool_member=%s WHERE launcher_id=%s",
Expand All @@ -164,7 +162,7 @@ async def update_singleton(
await connection.commit()

async def get_pay_to_singleton_phs(self) -> Set[bytes32]:
with (await self.pool) as connection:
with await self.pool as connection:
cursor = await connection.cursor()
await cursor.execute("SELECT p2_singleton_puzzle_hash from farmer")
rows = await cursor.fetchall()
Expand All @@ -179,7 +177,7 @@ async def get_farmer_records_for_p2_singleton_phs(self, puzzle_hashes: Set[bytes
if len(puzzle_hashes) == 0:
return []
puzzle_hashes_db = tuple([ph.hex() for ph in list(puzzle_hashes)])
with (await self.pool) as connection:
with await self.pool as connection:
cursor = await connection.cursor()
await cursor.execute(
f'SELECT * from farmer WHERE p2_singleton_puzzle_hash in ({"%s," * (len(puzzle_hashes_db) - 1)}%s) ',
Expand All @@ -190,7 +188,7 @@ async def get_farmer_records_for_p2_singleton_phs(self, puzzle_hashes: Set[bytes
return [self._row_to_farmer_record(row) for row in rows]

async def get_farmer_points_and_payout_instructions(self) -> List[Tuple[uint64, bytes]]:
with (await self.pool) as connection:
with await self.pool as connection:
cursor = await connection.cursor()
await cursor.execute(f"SELECT points, payout_instructions FROM farmer")
rows = await cursor.fetchall()
Expand All @@ -210,21 +208,21 @@ async def get_farmer_points_and_payout_instructions(self) -> List[Tuple[uint64,
return ret

async def clear_farmer_points(self) -> None:
with (await self.pool) as connection:
with await self.pool as connection:
cursor = await connection.cursor()
await cursor.execute(f"UPDATE farmer SET points=0")
await cursor.close()
await connection.commit()

async def add_partial(self, launcher_id: bytes32, timestamp: uint64, difficulty: uint64):
with (await self.pool) as connection:
with await self.pool as connection:
cursor = await connection.cursor()
await cursor.execute(
"INSERT INTO partial VALUES(%s, %s, %s)",
(launcher_id.hex(), timestamp, difficulty),
)
await connection.commit()
with (await self.pool) as connection:
with await self.pool as connection:
cursor = await connection.cursor()
await cursor.execute(
f"UPDATE farmer SET points=points+%s WHERE launcher_id=%s", (difficulty, launcher_id.hex())
Expand All @@ -233,7 +231,7 @@ async def add_partial(self, launcher_id: bytes32, timestamp: uint64, difficulty:
await cursor.close()

async def get_recent_partials(self, launcher_id: bytes32, count: int) -> List[Tuple[uint64, uint64]]:
with (await self.pool) as connection:
with await self.pool as connection:
cursor = await connection.cursor()
await cursor.execute(
"SELECT timestamp, difficulty from partial WHERE launcher_id=%s ORDER BY timestamp DESC LIMIT %s",
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import setuptools
from setuptools import setup


# Utility function to read the README file.
# Used for the long_description. It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
Expand Down
1 change: 0 additions & 1 deletion tests/test_difficulty.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class TestDifficulty(unittest.TestCase):
def test_no_things_in_db(self):

time_target = 24 * 3600
current_time = uint64(time.time())
assert get_new_difficulty([], 300, time_target, 10, current_time, 1) == 10
Expand Down