From 64a0d8d5dfa2cbd738b6de9b6e8effb23a2babe1 Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Fri, 10 Mar 2023 17:42:07 +0100 Subject: [PATCH] Remove some unused imports (and address black formatting as pointed by CI). Addresses issue #286. --- pool/pool.py | 1 - pool/pool_server.py | 1 - pool/singleton.py | 2 +- pool/store/mariadb_store.py | 24 +++++++++++------------- setup.py | 1 + tests/test_difficulty.py | 1 - 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/pool/pool.py b/pool/pool.py index e3472e3d..3bb0eade 100644 --- a/pool/pool.py +++ b/pool/pool.py @@ -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 diff --git a/pool/pool_server.py b/pool/pool_server.py index 3a073ef3..e50869c3 100644 --- a/pool/pool_server.py +++ b/pool/pool_server.py @@ -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) diff --git a/pool/singleton.py b/pool/singleton.py index f75709ac..8951dd25 100644 --- a/pool/singleton.py +++ b/pool/singleton.py @@ -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 diff --git a/pool/store/mariadb_store.py b/pool/store/mariadb_store.py index 9c3dcafd..5e3ef436 100644 --- a/pool/store/mariadb_store.py +++ b/pool/store/mariadb_store.py @@ -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 @@ -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) " @@ -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", @@ -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( @@ -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", @@ -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() @@ -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) ', @@ -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() @@ -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()) @@ -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", diff --git a/setup.py b/setup.py index 45b1c499..d35c105c 100644 --- a/setup.py +++ b/setup.py @@ -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 diff --git a/tests/test_difficulty.py b/tests/test_difficulty.py index 9890add0..390e0ae8 100644 --- a/tests/test_difficulty.py +++ b/tests/test_difficulty.py @@ -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