From 76615791f64a9afaad856641ed069f9f955c622f Mon Sep 17 00:00:00 2001 From: Mariano Date: Wed, 19 May 2021 20:42:34 +0900 Subject: [PATCH] Make the payment to the users --- pool.py | 11 ++++++++--- pool_server.py | 6 ++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pool.py b/pool.py index 223c9eb6..c4a95bc2 100644 --- a/pool.py +++ b/pool.py @@ -143,6 +143,7 @@ def __init__(self, private_key: PrivateKey, config: Dict, constants: ConsensusCo self.collect_pool_rewards_loop_task: Optional[asyncio.Task] = None self.create_payment_loop_task: Optional[asyncio.Task] = None self.submit_payment_loop_task: Optional[asyncio.Task] = None + self.get_peak_loop_task: Optional[asyncio.Task] = None self.node_rpc_client: Optional[FullNodeRpcClient] = None self.wallet_rpc_client: Optional[WalletRpcClient] = None @@ -170,6 +171,7 @@ async def start(self): self.collect_pool_rewards_loop_task = asyncio.create_task(self.collect_pool_rewards_loop()) self.create_payment_loop_task = asyncio.create_task(self.create_payment_loop()) self.submit_payment_loop_task = asyncio.create_task(self.submit_payment_loop()) + self.get_peak_loop_task = asyncio.create_task(self.get_peak_loop()) self.pending_payments = asyncio.Queue() @@ -182,6 +184,8 @@ async def stop(self): self.create_payment_loop_task.cancel() if self.submit_payment_loop_task is not None: self.submit_payment_loop_task.cancel() + if self.get_peak_loop_task is not None: + self.get_peak_loop_task.cancel() self.wallet_rpc_client.close() await self.wallet_rpc_client.await_closed() @@ -306,7 +310,7 @@ async def create_payment_loop(self): continue if self.pending_payments.qsize() != 0: - self.log.warning("Pending payments, waiting") + self.log.warning(f"Pending payments ({self.pending_payments.qsize()}), waiting") await asyncio.sleep(60) continue @@ -377,6 +381,7 @@ async def submit_payment_loop(self): try: peak_height = self.blockchain_state["peak"].height if not self.blockchain_state["sync"]["synced"] or not self.wallet_synced: + self.log.warning("Waiting for wallet sync") await asyncio.sleep(60) continue @@ -389,7 +394,7 @@ async def submit_payment_loop(self): # fee itself. Alternatively you can set it to 0 and wait longer blockchain_fee = 0.00001 * (10 ** 12) * len(payment_targets) try: - response = await self.wallet_rpc_client.send_transaction_multi( + transaction: TransactionRecord = await self.wallet_rpc_client.send_transaction_multi( self.wallet_id, payment_targets, fee=blockchain_fee ) except ValueError as e: @@ -397,7 +402,7 @@ async def submit_payment_loop(self): await self.pending_payments.put(payment_targets) continue - transaction: TransactionRecord = response["transaction"] + self.log.info(f"Transaction: {transaction}") while ( not transaction.confirmed diff --git a/pool_server.py b/pool_server.py index 4b9bd828..86c122b8 100644 --- a/pool_server.py +++ b/pool_server.py @@ -71,7 +71,6 @@ async def get_pool_info(self, _) -> web.Response: async def submit_partial(self, request_obj) -> web.Response: start_time = time.time() request = await request_obj.json() - self.pool.log.info(f"Received request: for {request['payload']['singleton_genesis']}") # TODO(pool): add rate limiting partial: SubmitPartial = SubmitPartial.from_json_dict(request) time_received_partial = uint64(int(time.time())) @@ -107,7 +106,10 @@ async def await_and_call(cor, *args): await_and_call(self.pool.process_partial, partial, time_received_partial, balance, curr_difficulty) ) - self.pool.log.info(f"Returning {res_dict}, time: {time.time() - start_time}") + self.pool.log.info( + f"Returning {res_dict}, time: {time.time() - start_time} " + f"singleton: {request['payload']['singleton_genesis']}" + ) return obj_to_response(res_dict)