Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#704 #705 Prometheus statistics export fixes #707

Merged
merged 5 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions proxy/common_neon/solana_interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
14 changes: 0 additions & 14 deletions proxy/statistics_exporter/prometheus_proxy_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 0 additions & 15 deletions proxy/statistics_exporter/prometheus_proxy_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions proxy/statistics_exporter/prometheus_proxy_server.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -54,7 +56,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
Expand Down
8 changes: 0 additions & 8 deletions proxy/statistics_exporter/proxy_metrics_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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"""