From 21ddee22cd07d7f67a4de137d8e9e8c5a3720cd6 Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Thu, 7 Apr 2022 14:59:56 +0300 Subject: [PATCH 1/3] #705 Fix 'AccountInfoLayout' is not defined error --- proxy/common_neon/solana_interactor.py | 28 +++++++++---------- .../prometheus_proxy_server.py | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/proxy/common_neon/solana_interactor.py b/proxy/common_neon/solana_interactor.py index d3bf25813..a9156b9ca 100644 --- a/proxy/common_neon/solana_interactor.py +++ b/proxy/common_neon/solana_interactor.py @@ -342,19 +342,7 @@ def get_neon_account_info(self, eth_account: EthereumAddress) -> Optional[NeonAc f"{len(info.data)} < {ACCOUNT_INFO_LAYOUT.sizeof()}") return NeonAccountInfo.frombytes(info.data) - def get_storage_account_info(self, storage_account: PublicKey) -> Optional[StorageAccountInfo]: - info = self.get_account_info(storage_account, length=0) - if info is None: - return None - elif info.tag != 30: - self.debug(f'Storage account {str(storage_account)} has tag {info.tag}') - return None - elif len(info.data) < STORAGE_ACCOUNT_INFO_LAYOUT.sizeof(): - raise RuntimeError(f"Wrong data length for storage data {storage_account}: " + - f"{len(info.data)} < {STORAGE_ACCOUNT_INFO_LAYOUT.sizeof()}") - return StorageAccountInfo.frombytes(info.data) - - def get_account_info_layout_list(self, eth_accounts: List[EthereumAddress]) -> List[Optional[AccountInfoLayout]]: + def get_neon_account_info_list(self, eth_accounts: List[EthereumAddress]) -> List[Optional[NeonAccountInfo]]: requests_list = [] for eth_account in eth_accounts: account_sol, _nonce = ether2program(eth_account) @@ -365,9 +353,21 @@ def get_account_info_layout_list(self, eth_accounts: List[EthereumAddress]) -> L if info is None or len(info.data) < ACCOUNT_INFO_LAYOUT.sizeof(): accounts_list.append(None) continue - accounts_list.append(AccountInfoLayout.frombytes(info.data)) + accounts_list.append(NeonAccountInfo.frombytes(info.data)) return accounts_list + def get_storage_account_info(self, storage_account: PublicKey) -> Optional[StorageAccountInfo]: + info = self.get_account_info(storage_account, length=0) + if info is None: + return None + elif info.tag != 30: + self.debug(f'Storage account {str(storage_account)} has tag {info.tag}') + return None + elif len(info.data) < STORAGE_ACCOUNT_INFO_LAYOUT.sizeof(): + raise RuntimeError(f"Wrong data length for storage data {storage_account}: " + + f"{len(info.data)} < {STORAGE_ACCOUNT_INFO_LAYOUT.sizeof()}") + return StorageAccountInfo.frombytes(info.data) + def get_multiple_rent_exempt_balances_for_size(self, size_list: [int], commitment='confirmed') -> [int]: opts = { "commitment": commitment diff --git a/proxy/statistics_exporter/prometheus_proxy_server.py b/proxy/statistics_exporter/prometheus_proxy_server.py index aefd26c51..757d557da 100644 --- a/proxy/statistics_exporter/prometheus_proxy_server.py +++ b/proxy/statistics_exporter/prometheus_proxy_server.py @@ -54,7 +54,7 @@ def _stat_operator_balance(self): self.stat_exporter.stat_commit_operator_sol_balance(str(account), Decimal(balance) / 1_000_000_000) neon_accounts = [str(EthereumAddress.from_private_key(neon_account.secret_key())) for neon_account in operator_accounts] - neon_layouts = self._solana.get_account_info_layout_list(neon_accounts) + neon_layouts = self._solana.get_neon_account_info_list(neon_accounts) for sol_account, neon_account, neon_layout in zip(operator_accounts, neon_accounts, neon_layouts): if neon_layout: neon_balance = Decimal(neon_layout.balance) / 1_000_000_000 / 1_000_000_000 From 3e7819cb72bbe0ae2b098ad42655819338f655b5 Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Thu, 7 Apr 2022 15:52:19 +0300 Subject: [PATCH 2/3] #705 fix logging error --- proxy/statistics_exporter/prometheus_proxy_server.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/proxy/statistics_exporter/prometheus_proxy_server.py b/proxy/statistics_exporter/prometheus_proxy_server.py index 757d557da..21628c55f 100644 --- a/proxy/statistics_exporter/prometheus_proxy_server.py +++ b/proxy/statistics_exporter/prometheus_proxy_server.py @@ -1,17 +1,19 @@ -from decimal import Decimal -from multiprocessing import Process import time import traceback -from typing import Dict, Tuple +from decimal import Decimal +from logged_groups import logged_group +from multiprocessing import Process + from prometheus_client import start_http_server from proxy.common_neon.address import EthereumAddress from proxy.common_neon.solana_interactor import SolanaInteractor - from proxy.environment import PP_SOLANA_URL, PYTH_MAPPING_ACCOUNT, SOLANA_URL, get_solana_accounts from proxy.plugin.gas_price_calculator import GasPriceCalculator + from .prometheus_proxy_exporter import PrometheusExporter +@logged_group("neon.ProxyStatExporter") class PrometheusProxyServer: def __init__(self): self.start_http_server() From a25a442ceabe62dcb234b111ed4cc0ded90cf531 Mon Sep 17 00:00:00 2001 From: Dmitriy Borisenko Date: Thu, 7 Apr 2022 15:59:54 +0300 Subject: [PATCH 3/3] Remove obsolete methods --- .../prometheus_proxy_exporter.py | 14 -------------- .../prometheus_proxy_metrics.py | 15 --------------- .../proxy_metrics_interface.py | 8 -------- 3 files changed, 37 deletions(-) diff --git a/proxy/statistics_exporter/prometheus_proxy_exporter.py b/proxy/statistics_exporter/prometheus_proxy_exporter.py index 51fc2e353..dabf10ada 100644 --- a/proxy/statistics_exporter/prometheus_proxy_exporter.py +++ b/proxy/statistics_exporter/prometheus_proxy_exporter.py @@ -31,14 +31,6 @@ def stat_commit_tx_end_failed(self, _err: Exception): TX_FAILED.inc() TX_IN_PROGRESS.dec() - def stat_commit_tx_balance_change(self, sol_acc: str, sol_diff: Decimal, neon_acc: str, neon_diff: Decimal): - from .prometheus_proxy_metrics import ( - OPERATOR_SOL_BALANCE_DIFF, - OPERATOR_NEON_BALANCE_DIFF, - ) - OPERATOR_SOL_BALANCE_DIFF.labels(sol_acc).set(sol_diff) - OPERATOR_NEON_BALANCE_DIFF.labels(neon_acc).set(neon_diff) - def stat_commit_operator_sol_balance(self, operator: str, sol_balance: Decimal): from .prometheus_proxy_metrics import ( OPERATOR_SOL_BALANCE @@ -51,12 +43,6 @@ def stat_commit_operator_neon_balance(self, sol_acc: str, neon_acc: str, neon_ba ) OPERATOR_NEON_BALANCE.labels(sol_acc, neon_acc).set(neon_balance) - def stat_commit_create_resource_account(self, account: str, rent: Decimal): - from .prometheus_proxy_metrics import ( - OPERATOR_ACCOUNT_RENT - ) - OPERATOR_ACCOUNT_RENT.labels(account).set(rent) - def stat_commit_gas_parameters(self, gas_price: int, sol_price_usd: Decimal, neon_price_usd: Decimal, operator_fee: Decimal): from .prometheus_proxy_metrics import ( USD_PRICE_NEON, USD_PRICE_SOL, OPERATOR_FEE, GAS_PRICE diff --git a/proxy/statistics_exporter/prometheus_proxy_metrics.py b/proxy/statistics_exporter/prometheus_proxy_metrics.py index 33a131d42..2930abc69 100644 --- a/proxy/statistics_exporter/prometheus_proxy_metrics.py +++ b/proxy/statistics_exporter/prometheus_proxy_metrics.py @@ -27,21 +27,6 @@ ['operator_sol_wallet', 'operator_neon_wallet'], registry=registry, ) -OPERATOR_SOL_BALANCE_DIFF = Gauge( - 'operator_sol_balance_diff', 'Operator Sol Balance Diff On TX', - ['operator_sol_wallet'], - registry=registry, -) -OPERATOR_NEON_BALANCE_DIFF = Gauge( - 'operator_neon_balance_diff', 'Operator Neon Balance Diff On TX', - ['operator_neon_wallet'], - registry=registry, -) -OPERATOR_ACCOUNT_RENT = Gauge( - 'operator_account_rent', 'Operator Account Rent', - ['account'], - registry=registry, -) USD_PRICE_SOL = Gauge( 'usd_price_sol', 'Sol Price USD', registry=registry, diff --git a/proxy/statistics_exporter/proxy_metrics_interface.py b/proxy/statistics_exporter/proxy_metrics_interface.py index 3b6d126b2..78b0c61f9 100644 --- a/proxy/statistics_exporter/proxy_metrics_interface.py +++ b/proxy/statistics_exporter/proxy_metrics_interface.py @@ -20,10 +20,6 @@ def stat_commit_tx_end_success(self): def stat_commit_tx_end_failed(self, err: Exception): """Add failed TX""" - @abstractmethod - def stat_commit_tx_balance_change(self, sol_acc: str, sol_diff: Decimal, neon_acc: str, neon_diff: Decimal): - """Operator Sol and Neon balance changes on TX""" - @abstractmethod def stat_commit_operator_sol_balance(self, operator: str, sol_balance: Decimal): """Operator Balance in Sol\'s""" @@ -32,10 +28,6 @@ def stat_commit_operator_sol_balance(self, operator: str, sol_balance: Decimal): def stat_commit_operator_neon_balance(self, sol_acc: str, neon_acc: str, neon_balance: Decimal): """Operator Balance in Neon\'s""" - @abstractmethod - def stat_commit_create_resource_account(self, account: str, rent: Decimal): - """Created resource account and its rent""" - @abstractmethod def stat_commit_gas_parameters(self, gas_price: int, sol_price_usd: Decimal, neon_price_usd: Decimal, operator_fee: Decimal): """GAS Parameters"""