Skip to content

Commit

Permalink
limit concurrency to 50 parallel txs
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazabbas committed Aug 15, 2024
1 parent b369694 commit 760ab22
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions program_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
"pythtest": "https://api.pythtest.pyth.network",
}

MAX_CONCURRENT_TRANSACTIONS = 50


class ProgramAdmin:
network: Network
Expand Down Expand Up @@ -261,7 +263,7 @@ async def sync(

# Sync product/price accounts

transactions: List[asyncio.Task[None]] = []
product_transactions: List[asyncio.Task[None]] = []

product_updates: bool = False

Expand All @@ -281,22 +283,27 @@ async def sync(

instructions.extend(product_instructions)
if send_transactions:
transactions.append(
product_transactions.append(
asyncio.create_task(
self.send_transaction(
product_instructions, product_keypairs
)
)
)

await asyncio.gather(*transactions)
if len(product_transactions) == MAX_CONCURRENT_TRANSACTIONS:
await asyncio.gather(*product_transactions)
product_transactions = []

if product_transactions:
await asyncio.gather(*product_transactions)

if product_updates:
await self.refresh_program_accounts()

# Sync publishers

transactions = []
publisher_transactions = []

for jump_symbol, _price_account_map in ref_permissions.items():
ref_product = ref_products[jump_symbol] # type: ignore
Expand All @@ -311,13 +318,18 @@ async def sync(
if price_instructions:
instructions.extend(price_instructions)
if send_transactions:
transactions.append(
publisher_transactions.append(
asyncio.create_task(
self.send_transaction(price_instructions, price_keypairs)
)
)

await asyncio.gather(*transactions)
if len(publisher_transactions) == MAX_CONCURRENT_TRANSACTIONS:
await asyncio.gather(*publisher_transactions)
publisher_transactions = []

if publisher_transactions:
await asyncio.gather(*publisher_transactions)

return instructions

Expand Down

0 comments on commit 760ab22

Please sign in to comment.