Skip to content

Commit

Permalink
- fix parameter --axon.external_ip
Browse files Browse the repository at this point in the history
- add tracing for a gas used amount and a transaction message
  • Loading branch information
Snedashkovsky committed Mar 31, 2024
1 parent e8168ac commit c11e193
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
13 changes: 3 additions & 10 deletions cybertensor/axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from starlette.responses import Response

import cybertensor
import cybertensor.utils.networking as net
from cybertensor.config import Config
from cybertensor.errors import *
from cybertensor.keypair import Keypair
Expand Down Expand Up @@ -309,16 +310,8 @@ def __init__(
self.uuid = str(uuid.uuid1())
self.ip = self.config.axon.ip
self.port = self.config.axon.port
self.external_ip = (
self.config.axon.external_ip
if self.config.axon.external_ip is not None
else cybertensor.utils.networking.get_external_ip()
)
self.external_port = (
self.config.axon.external_port
if self.config.axon.external_port is not None
else self.config.axon.port
)
self.external_ip = self.config.axon.external_ip or net.get_external_ip()
self.external_port = self.config.axon.external_port or self.config.axon.port
self.full_address = str(self.config.axon.ip) + ":" + str(self.config.axon.port)
self.started = False

Expand Down
28 changes: 15 additions & 13 deletions cybertensor/cwtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ def make_call_with_retry(self, wait_for_finalization: bool,
return True
else:
try:
# NOTE will raise exeption if tx simulation is not successful, need to catch it
# NOTE will raise exception if tx simulation is not successful, need to catch it
tx = self.contract.execute(msg, signer_wallet, gas, funds=funds)
except Exception as e:
raise error(e.__str__())
try:
tx.wait_to_complete()
if tx.response.is_successful():
print(f'Gas used: {tx.response.gas_used}')
cybertensor.logging.trace(f'Gas used: {tx.response.gas_used}')
return True
else:
raise error(tx.response.logs)
Expand All @@ -375,6 +375,7 @@ def _execute_contract(self, wait_for_finalization: bool,
signer_wallet = LocalWallet(
PrivateKey(_private_key), self.address_prefix
)
cybertensor.logging.trace(f'tx msg {msg}\tsigner_wallet {signer_wallet}')
res = self.make_call_with_retry(
wait_for_finalization=wait_for_finalization,
msg=msg,
Expand Down Expand Up @@ -406,12 +407,13 @@ def _execute_contract(self, wait_for_finalization: bool,
def make_call_with_retry_2(self, wait_for_finalization: bool,
msg: dict, signer_wallet: LocalWallet, gas: Optional[int] = cybertensor.__default_gas__,
funds: Optional[str] = None) -> [bool, Optional[str]]:
cybertensor.logging.trace(f'tx msg {msg}\tsigner_wallet {signer_wallet}')
if not wait_for_finalization:
self.contract.execute(msg, signer_wallet, gas, funds=funds)
return True, None
else:
try:
# NOTE will raise exeption if tx simulation is not successful, need to catch it
# NOTE will raise exception if tx simulation is not successful, need to catch it
tx = self.contract.execute(msg, signer_wallet, gas, funds=funds)
except Exception as e:
return False, e.__str__()
Expand All @@ -426,9 +428,9 @@ def make_call_with_retry_2(self, wait_for_finalization: bool,
except Exception as e:
return False, e.__str__()

####################
#### Websocket Interface related
####################
#####################################
#### Websocket Interface related ####
#####################################
def connect_websocket(self):
"""
(Re)creates the websocket connection, if the URL contains a 'ws' or 'wss' scheme
Expand Down Expand Up @@ -1466,9 +1468,9 @@ def root_set_weights(
prompt=prompt,
)

#####################################
#### Hyper parameter calls. ####
#####################################
###############################
#### Hyper parameter calls ####
###############################

def difficulty(self, netuid: int, block: Optional[int] = None) -> Optional[int]:
"""
Expand Down Expand Up @@ -1758,9 +1760,9 @@ def tx_rate_limit(self, block: Optional[int] = None) -> Optional[int]:
"""
return self.contract.query({"get_tx_rate_limit": {}})

#####################################
############################
#### Network Parameters ####
#####################################
############################

def get_subnet_burn_cost(self, block: Optional[int] = None) -> Optional[int]:
lock_cost = self.contract.query({"get_network_registration_cost": {}})
Expand Down Expand Up @@ -2101,9 +2103,9 @@ def get_stake_info_for_coldkeys(

return StakeInfo.list_of_tuple_from_list_any(result)

########################################
#######################################
#### Neuron information per subnet ####
########################################
#######################################

def is_hotkey_registered_any(
self, hotkey: str, block: Optional[int] = None
Expand Down
4 changes: 2 additions & 2 deletions cybertensor/messages/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ def prometheus_message(
or returns ``false`` if the extrinsic fails to be finalized within the timeout.
Returns:
success (bool):
Flag is ``true`` if extrinsic was finalized or uncluded in the block.
Flag is ``true`` if extrinsic was finalized or included in the block.
If we did not wait for finalization / inclusion, the response is ``true``.
"""

# ---- Get external ip ----
if ip is None:
try:
external_ip = net.get_external_ip()
external_ip = cwtensor.config.axon.external_ip or net.get_external_ip()
console.print(
f":white_heavy_check_mark: [green]Found external ip: {external_ip}[/green]"
)
Expand Down
2 changes: 1 addition & 1 deletion cybertensor/messages/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def serve_axon_message(
# ---- Get external ip ----
if axon.external_ip is None:
try:
external_ip = net.get_external_ip()
external_ip = cwtensor.config.axon.external_ip or net.get_external_ip()
console.print(
f":white_heavy_check_mark: [green]Found external ip: {external_ip}[/green]"
)
Expand Down

0 comments on commit c11e193

Please sign in to comment.