@@ -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_payments := await self .store . get_pending_payment_count () ) != 0 :
361
+ self .log .warning (f"Pending payments ({ pending_payments } ), 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,38 @@ 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
+ pending_payments = await self .store .get_pending_payment_records (self .max_additions_per_transaction )
442
+ if len (pending_payments ) == 0 :
443
+ self .log .info ("No funds to pending payments record" )
444
+ await asyncio .sleep (60 )
445
+ continue
446
+ self .log .info (f"Submitting a payment: { pending_payments } " )
446
447
447
- self .log .info (f"Submitting a payment: { payment_targets } " )
448
+ payment_targets : List [Dict ] = [
449
+ {
450
+ "puzzle_hash" : puzzle_hash ,
451
+ "amount" : amount ,
452
+ }
453
+ for puzzle_hash , amount , _ , _ in pending_payments
454
+ ]
448
455
449
456
# TODO(pool): make sure you have enough to pay the blockchain fee, this will be taken out of the pool
450
457
# fee itself. Alternatively you can set it to 0 and wait longer
451
458
# blockchain_fee = 0.00001 * (10 ** 12) * len(payment_targets)
452
459
blockchain_fee = 0
453
460
try :
461
+ await self .store .update_is_payment (
462
+ [(puzzle_hash , timestamp ) for puzzle_hash , _ , timestamp , _ in pending_payments ], True
463
+ )
454
464
transaction : TransactionRecord = await self .wallet_rpc_client .send_transaction_multi (
455
465
self .wallet_id , payment_targets , fee = blockchain_fee
456
466
)
457
- except ValueError as e :
467
+ except Exception as e :
458
468
self .log .error (f"Error making payment: { e } " )
469
+ await self .store .update_is_payment (
470
+ [(puzzle_hash , timestamp ) for puzzle_hash , _ , timestamp , _ in pending_payments ], False
471
+ )
459
472
await asyncio .sleep (10 )
460
- await self .pending_payments .put (payment_targets )
461
473
continue
462
474
463
475
self .log .info (f"Transaction: { transaction } " )
0 commit comments