Skip to content

Commit

Permalink
Make the payment to the users
Browse files Browse the repository at this point in the history
  • Loading branch information
mariano54 committed May 19, 2021
1 parent cd6be54 commit 7661579
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -389,15 +394,15 @@ 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:
self.log.error(f"Error making payment: {e}")
await self.pending_payments.put(payment_targets)
continue

transaction: TransactionRecord = response["transaction"]
self.log.info(f"Transaction: {transaction}")

while (
not transaction.confirmed
Expand Down
6 changes: 4 additions & 2 deletions pool_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit 7661579

Please sign in to comment.