1
+ import asyncio
1
2
import json
2
3
import os
3
4
from pathlib import Path
47
48
"pythtest" : "https://api.pythtest.pyth.network" ,
48
49
}
49
50
51
+ MAX_CONCURRENT_TRANSACTIONS = 50
52
+
50
53
51
54
class ProgramAdmin :
52
55
network : Network
@@ -260,6 +263,8 @@ async def sync(
260
263
261
264
# Sync product/price accounts
262
265
266
+ product_transactions : List [asyncio .Task [None ]] = []
267
+
263
268
product_updates : bool = False
264
269
265
270
for jump_symbol , _price_account_map in ref_permissions .items ():
@@ -278,12 +283,28 @@ async def sync(
278
283
279
284
instructions .extend (product_instructions )
280
285
if send_transactions :
281
- await self .send_transaction (product_instructions , product_keypairs )
286
+ product_transactions .append (
287
+ asyncio .create_task (
288
+ self .send_transaction (
289
+ product_instructions , product_keypairs
290
+ )
291
+ )
292
+ )
293
+
294
+ if len (product_transactions ) == MAX_CONCURRENT_TRANSACTIONS :
295
+ await asyncio .gather (* product_transactions )
296
+ product_transactions = []
297
+
298
+ if product_transactions :
299
+ await asyncio .gather (* product_transactions )
282
300
283
301
if product_updates :
284
302
await self .refresh_program_accounts ()
285
303
286
304
# Sync publishers
305
+
306
+ publisher_transactions = []
307
+
287
308
for jump_symbol , _price_account_map in ref_permissions .items ():
288
309
ref_product = ref_products [jump_symbol ] # type: ignore
289
310
@@ -297,7 +318,18 @@ async def sync(
297
318
if price_instructions :
298
319
instructions .extend (price_instructions )
299
320
if send_transactions :
300
- await self .send_transaction (price_instructions , price_keypairs )
321
+ publisher_transactions .append (
322
+ asyncio .create_task (
323
+ self .send_transaction (price_instructions , price_keypairs )
324
+ )
325
+ )
326
+
327
+ if len (publisher_transactions ) == MAX_CONCURRENT_TRANSACTIONS :
328
+ await asyncio .gather (* publisher_transactions )
329
+ publisher_transactions = []
330
+
331
+ if publisher_transactions :
332
+ await asyncio .gather (* publisher_transactions )
301
333
302
334
return instructions
303
335
0 commit comments