Skip to content

Commit

Permalink
Parallelize account and publisher sync
Browse files Browse the repository at this point in the history
  • Loading branch information
mcamou committed Aug 14, 2024
1 parent edf8567 commit 9efc689
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions program_admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from asyncio import Future
import asyncio
import json
import os
from pathlib import Path
from typing import Dict, List, Literal, Optional, Tuple
from typing import Any, Coroutine, Dict, List, Literal, Optional, Tuple

from loguru import logger
from solana import system_program
Expand Down Expand Up @@ -260,6 +262,8 @@ async def sync(

# Sync product/price accounts

transactions: list[Coroutine[Any, Any, None]] = []

product_updates: bool = False

for jump_symbol, _price_account_map in ref_permissions.items():
Expand All @@ -278,12 +282,17 @@ async def sync(

instructions.extend(product_instructions)
if send_transactions:
await self.send_transaction(product_instructions, product_keypairs)
transactions.append(self.send_transaction(product_instructions, product_keypairs))

await asyncio.gather(*transactions)

if product_updates:
await self.refresh_program_accounts()

# Sync publishers

transactions = []

for jump_symbol, _price_account_map in ref_permissions.items():
ref_product = ref_products[jump_symbol] # type: ignore

Expand All @@ -297,7 +306,9 @@ async def sync(
if price_instructions:
instructions.extend(price_instructions)
if send_transactions:
await self.send_transaction(price_instructions, price_keypairs)
transactions.append(self.send_transaction(price_instructions, price_keypairs))

await asyncio.gather(*transactions)

return instructions

Expand Down

0 comments on commit 9efc689

Please sign in to comment.