@@ -155,9 +155,6 @@ def __init__(
155
155
# faster.
156
156
self .max_additions_per_transaction = pool_config ["max_additions_per_transaction" ]
157
157
158
- # This is the list of payments that we have not sent yet, to farmers
159
- self .pending_payments : Optional [asyncio .Queue ] = None
160
-
161
158
# Keeps track of the latest state of our node
162
159
self .blockchain_state = {"peak" : None }
163
160
@@ -207,8 +204,6 @@ async def start(self):
207
204
self .submit_payment_loop_task = asyncio .create_task (self .submit_payment_loop ())
208
205
self .get_peak_loop_task = asyncio .create_task (self .get_peak_loop ())
209
206
210
- self .pending_payments = asyncio .Queue ()
211
-
212
207
async def stop (self ):
213
208
if self .confirm_partials_loop_task is not None :
214
209
self .confirm_partials_loop_task .cancel ()
@@ -362,8 +357,8 @@ async def create_payment_loop(self):
362
357
await asyncio .sleep (60 )
363
358
continue
364
359
365
- if self .pending_payments . qsize ( ) != 0 :
366
- self .log .warning (f"Pending payments ({ self . pending_payments . qsize () } ), waiting" )
360
+ if ( pending_payment_count := await self .store . get_payment_count_by_is_payment ( False ) ) != 0 :
361
+ self .log .warning (f"Pending payments ({ pending_payment_count } ), waiting" )
367
362
await asyncio .sleep (60 )
368
363
continue
369
364
@@ -408,14 +403,16 @@ async def create_payment_loop(self):
408
403
if points > 0 :
409
404
additions_sub_list .append ({"puzzle_hash" : ph , "amount" : points * mojo_per_point })
410
405
411
- if len (additions_sub_list ) == self .max_additions_per_transaction :
412
- await self .pending_payments .put (additions_sub_list .copy ())
413
- self .log .info (f"Will make payments: { additions_sub_list } " )
414
- additions_sub_list = []
406
+ for payment in additions_sub_list :
407
+ await self .store .add_payment (
408
+ payment ["puzzle_hash" ],
409
+ uint64 (payment ["amount" ]),
410
+ uint64 (int (time .time ())),
411
+ False ,
412
+ )
415
413
416
414
if len (additions_sub_list ) > 0 :
417
415
self .log .info (f"Will make payments: { additions_sub_list } " )
418
- await self .pending_payments .put (additions_sub_list .copy ())
419
416
420
417
# Subtract the points from each farmer
421
418
await self .store .clear_farmer_points ()
@@ -441,23 +438,40 @@ async def submit_payment_loop(self):
441
438
await asyncio .sleep (60 )
442
439
continue
443
440
444
- payment_targets = await self .pending_payments .get ()
445
- assert len (payment_targets ) > 0
441
+ payment_records = await self .store .get_payment_records_by_is_payment (
442
+ False , self .max_additions_per_transaction
443
+ )
444
+ if len (payment_records ) == 0 :
445
+ self .log .info ("No funds to payment record" )
446
+ await asyncio .sleep (60 )
447
+ continue
446
448
447
- self .log .info (f"Submitting a payment: { payment_targets } " )
449
+ payment_targets : List [Dict ] = [
450
+ {
451
+ "puzzle_hash" : puzzle_hash ,
452
+ "amount" : amount ,
453
+ }
454
+ for puzzle_hash , amount , _ , _ in payment_records
455
+ ]
456
+ self .log .info (f"Submitting a payment: { payment_records } " )
448
457
449
458
# TODO(pool): make sure you have enough to pay the blockchain fee, this will be taken out of the pool
450
459
# fee itself. Alternatively you can set it to 0 and wait longer
451
460
# blockchain_fee = 0.00001 * (10 ** 12) * len(payment_targets)
452
461
blockchain_fee = 0
453
462
try :
463
+ await self .store .update_payments_is_payment (
464
+ [(puzzle_hash , timestamp ) for puzzle_hash , _ , timestamp , _ in payment_records ], True
465
+ )
454
466
transaction : TransactionRecord = await self .wallet_rpc_client .send_transaction_multi (
455
467
self .wallet_id , payment_targets , fee = blockchain_fee
456
468
)
457
- except ValueError as e :
469
+ except Exception as e :
458
470
self .log .error (f"Error making payment: { e } " )
471
+ await self .store .update_payments_is_payment (
472
+ [(puzzle_hash , timestamp ) for puzzle_hash , _ , timestamp , _ in payment_records ], False
473
+ )
459
474
await asyncio .sleep (10 )
460
- await self .pending_payments .put (payment_targets )
461
475
continue
462
476
463
477
self .log .info (f"Transaction: { transaction } " )
0 commit comments