Skip to content

Commit

Permalink
[AUD-1338] Consolidate batch size for indexing across sol tasks (#2391)
Browse files Browse the repository at this point in the history
* Ensure user bank and rewards manager indexing have identical batch configs to plays for speedier processing
  • Loading branch information
hareeshnagaraj authored and raymondjacobson committed Jan 27, 2022
1 parent 9200772 commit 64c5977
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
9 changes: 9 additions & 0 deletions discovery-provider/src/solana/constants.py
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
WAUDIO_DECIMALS = 8

# The size of the tx signatures for the program coming from the RPC pool per batch
TX_SIGNATURES_BATCH_SIZE = 1000

# Maximum number of batches to process at once
TX_SIGNATURES_MAX_BATCHES = 100

# Last N entries present in tx_signatures array during processing
TX_SIGNATURES_RESIZE_LENGTH = 75
13 changes: 6 additions & 7 deletions discovery-provider/src/tasks/index_rewards_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
UserChallenge,
)
from src.queries.get_balances import enqueue_immediate_balance_refresh
from src.solana.constants import (
TX_SIGNATURES_BATCH_SIZE,
TX_SIGNATURES_MAX_BATCHES,
TX_SIGNATURES_RESIZE_LENGTH,
)
from src.solana.solana_client_manager import SolanaClientManager
from src.solana.solana_parser import (
InstructionFormat,
Expand Down Expand Up @@ -46,12 +51,6 @@
REWARDS_MANAGER_ACCOUNT = shared_config["solana"]["rewards_manager_account"]
MIN_SLOT = int(shared_config["solana"]["rewards_manager_min_slot"])

# Maximum number of batches to process at once
TX_SIGNATURES_MAX_BATCHES = 20

# Last N entries present in tx_signatures array during processing
TX_SIGNATURES_RESIZE_LENGTH = 10


def check_valid_rewards_manager_program():
try:
Expand Down Expand Up @@ -383,7 +382,7 @@ def get_transaction_signatures(
latest_processed_slot = get_latest_slot(session)
while not intersection_found:
transactions_history = solana_client_manager.get_signatures_for_address(
program, before=last_tx_signature, limit=100
program, before=last_tx_signature, limit=TX_SIGNATURES_BATCH_SIZE
)

transactions_array = transactions_history["result"]
Expand Down
14 changes: 5 additions & 9 deletions discovery-provider/src/tasks/index_solana_plays.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
from src.challenges.challenge_event import ChallengeEvent
from src.challenges.challenge_event_bus import ChallengeEventBus
from src.models import Play
from src.solana.constants import (
TX_SIGNATURES_BATCH_SIZE,
TX_SIGNATURES_MAX_BATCHES,
TX_SIGNATURES_RESIZE_LENGTH,
)
from src.solana.solana_client_manager import SolanaClientManager
from src.solana.solana_transaction_types import (
ConfirmedSignatureForAddressResult,
Expand Down Expand Up @@ -39,15 +44,6 @@

REDIS_TX_CACHE_QUEUE_PREFIX = "plays-tx-cache-queue"

# The size of the tx signatures for the program coming from the RPC pool per batch
TX_SIGNATURES_BATCH_SIZE = 1000

# Maximum number of batches to process at once
TX_SIGNATURES_MAX_BATCHES = 100

# Last N entries present in tx_signatures array during processing
TX_SIGNATURES_RESIZE_LENGTH = 75

# Number of signatures that are fetched from RPC and written at once
# For example, in a batch of 1000 only 100 will be fetched and written in parallel
# Intended to relieve RPC and DB pressure
Expand Down
15 changes: 8 additions & 7 deletions discovery-provider/src/tasks/index_user_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
from sqlalchemy.orm.session import Session
from src.models import User, UserBankAccount, UserBankTransaction
from src.queries.get_balances import enqueue_immediate_balance_refresh
from src.solana.constants import (
TX_SIGNATURES_BATCH_SIZE,
TX_SIGNATURES_MAX_BATCHES,
TX_SIGNATURES_RESIZE_LENGTH,
)
from src.solana.solana_client_manager import SolanaClientManager
from src.solana.solana_helpers import SPL_TOKEN_ID_PK, get_address_pair
from src.solana.solana_parser import (
Expand Down Expand Up @@ -47,12 +52,6 @@
# Used to limit tx history if needed
MIN_SLOT = int(shared_config["solana"]["user_bank_min_slot"])

# Maximum number of batches to process at once
TX_SIGNATURES_MAX_BATCHES = 3

# Last N entries present in tx_signatures array during processing
TX_SIGNATURES_RESIZE_LENGTH = 3


# Recover ethereum public key from bytes array
# Message formatted as follows:
Expand Down Expand Up @@ -286,7 +285,9 @@ def process_user_bank_txs():
logger.info(f"index_user_bank.py | high tx = {latest_processed_slot}")
while not intersection_found:
transactions_history = solana_client_manager.get_signatures_for_address(
USER_BANK_ADDRESS, before=last_tx_signature, limit=100
USER_BANK_ADDRESS,
before=last_tx_signature,
limit=TX_SIGNATURES_BATCH_SIZE,
)
transactions_array = transactions_history["result"]
if not transactions_array:
Expand Down

0 comments on commit 64c5977

Please sign in to comment.