Skip to content

Commit

Permalink
Merge pull request #16 from cybercongress/optimize_network_config
Browse files Browse the repository at this point in the history
Optimize network config and add space-pussy network
  • Loading branch information
cyborgshead authored Feb 1, 2024
2 parents d3c3a79 + 738efa8 commit 383a6ed
Show file tree
Hide file tree
Showing 19 changed files with 247 additions and 173 deletions.
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

## Install

From source:
1. From source:
```bash
git clone https://github.com/cybercongress/cybertensor.git
python3 -m pip install -e cybertensor/
```

To test your installation, type:
2. To test your installation, type:
```bash
ctcli --help
```
Expand All @@ -21,6 +20,32 @@ or using python
import cybertensor
```

## Space Pussy setup

1. Clone:
```bash
git clone https://github.com/cybercongress/cybertensor.git
cd cybertensor
git checkout optimize_network_config
```
2. [Optional] Create and activate a virtual environment:
```bash
python3 -m venv venv
. venv/bin/activate
```
3. Install from the source
```bash
python3 -m pip install -e .
```

4. To test your installation, type:
```bash
ctcli --help
```
or using python
```python
import cybertensor
```

## Dev setup
1. Use localbostrom:
Expand Down Expand Up @@ -64,4 +89,4 @@ tree ~/.cybertensor/contract
7. Register network:
```bash
ctcli s create
```
```
100 changes: 70 additions & 30 deletions cybertensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# DEALINGS IN THE SOFTWARE.

from pathlib import Path
from typing import Optional, Union

# Install and apply nest asyncio to allow the async functions
# to run in a .ipynb
Expand Down Expand Up @@ -75,7 +76,39 @@ def debug(on: bool = True):
logging.set_debug(on)


# Substrate chain block time (seconds).
class NetworkConfigCwTensor(NetworkConfig):
def __init__(
self,
chain_id: str,
fee_minimum_gas_price: Union[int, float],
fee_denomination: str,
staking_denomination: str,
url: str,
token: str,
token_symbol: str,
giga_token_symbol: str,
network_explorer: str,
address_prefix: str,
contract_address: str,
faucet_url: Optional[str] = None,
):
super().__init__(
chain_id,
fee_minimum_gas_price,
fee_denomination,
staking_denomination,
url,
faucet_url,
)
self.token = token
self.token_symbol = token_symbol
self.giga_token_symbol = giga_token_symbol
self.network_explorer = network_explorer
self.address_prefix = address_prefix
self.contract_address = contract_address


# Chain block time (seconds).
__blocktime__ = 6

# Pip address for versioning
Expand All @@ -85,57 +118,64 @@ def debug(on: bool = True):
# TODO add data to github
__delegates_details_url__: str = "https://raw.githubusercontent.com/cybercongress/cybertensor/main/public/delegates.json"

# Bostrom network address prefix
__chain_address_prefix__ = "bostrom"
# TODO move to NetworkConfigCwTensor
__chain_address_prefix__ = "pussy"
__boot_symbol__: str = "PUSSY"
__giga_boot_symbol__: str = "GPUSSY"

__networks__ = ["local", "bostrom"]
__networks__ = ["local", "bostrom", "space-pussy"]

__contracts__ = [
"bostrom14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sww4mxt",
"bostrom14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sww4mxt"
]

__local_network__ = NetworkConfig(
__local_network__ = NetworkConfigCwTensor(
chain_id="localbostrom",
url="grpc+http://localhost:9090",
fee_minimum_gas_price=0.1,
fee_denomination="boot",
staking_denomination="boot",
faucet_url="",
token="boot",
token_symbol="BOOT",
giga_token_symbol="GBOOT",
network_explorer="http://localhost:3000",
address_prefix="bostrom",
contract_address="bostrom14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sww4mxt",
)

__bostrom_network__ = NetworkConfig(
__bostrom_network__ = NetworkConfigCwTensor(
chain_id="bostrom",
url="grpc+http://localhost:9090",
fee_minimum_gas_price=0.1,
url="grpc+http://grpc.bostrom.cybernode.ai:1443",
fee_minimum_gas_price=0.01,
fee_denomination="boot",
staking_denomination="boot",
faucet_url="",
token="boot",
token_symbol="BOOT",
giga_token_symbol="GBOOT",
network_explorer="https://cyb.ai",
address_prefix="bostrom",
contract_address="bostrom14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sww4mxt",
)

__space_pussy_network__ = NetworkConfigCwTensor(
chain_id="space-pussy",
url="grpc+https://grpc.space-pussy.cybernode.ai:1443",
fee_minimum_gas_price=0.01,
fee_denomination="pussy",
staking_denomination="pussy",
faucet_url="",
token="pussy",
token_symbol="PUSSY",
giga_token_symbol="GPUSSY",
network_explorer="https://cyb.ai",
address_prefix="pussy",
contract_address="pussy1ddwq8rxgdsm27pvpxqdy2ep9enuen6t2yhrqujvj9qwl4dtukx0s8hpka9",
)

__contract_path__ = Path(__file__).home() / ".cybertensor/contract/cybernet.wasm"
__contract_schema_path__ = Path(__file__).home() / ".cybertensor/contract/schema"

__token__ = "boot"

__default_gas__ = 1_000_000
__default_transfer_gas__ = 100_000

__boot_symbol__: str = "BOOT"
__giga_boot_symbol__: str = "GBOOT"

# change to emoji here
# __boot_symbol__: str = chr(0x03C4)
# __oxygen_symbol__: str = chr(0x03C4)

# Block Explorers map network to explorer url
# TODO update explorer presets
__network_explorer_map__ = {
"local": "https://cyb.ai",
"bostrom": "https://cyb.ai",
"space-pussy": "https://cyb.ai",
}

from .errors import *
from .config import *
from .keyfile import *
Expand Down
2 changes: 1 addition & 1 deletion cybertensor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def __init__(
cli.check_config(self.config)

# If no_version_checking is not set or set as False in the config, version checking is done.
if not self.config.get("no_version_checking", d=True):
if self.config.get("no_version_checking", d=True):
try:
cybertensor.utils.version_checking()
except:
Expand Down
2 changes: 1 addition & 1 deletion cybertensor/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
defaults: Munch = munchify(
{
"netuid": 1,
"cwtensor": {"network": "local", "_mock": False},
"cwtensor": {"network": "space-pussy", "_mock": False},
"pow_register": {
"num_processes": None,
"update_interval": 50000,
Expand Down
60 changes: 25 additions & 35 deletions cybertensor/commands/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ def show_delegates(
"[overline white]NOMINATORS", justify="center", style="green", no_wrap=True
)
table.add_column(
"[overline white]DELEGATE STAKE(\u03C4)", justify="right", no_wrap=True
f"[overline white]DELEGATE STAKE({cwtensor.giga_token_symbol})", justify="right", no_wrap=True
)
table.add_column(
"[overline white]TOTAL STAKE(\u03C4)",
f"[overline white]TOTAL STAKE({cwtensor.giga_token_symbol})",
justify="right",
style="green",
no_wrap=True,
Expand All @@ -156,7 +156,7 @@ def show_delegates(
table.add_column("[overline white]VPERMIT", justify="right", no_wrap=False)
table.add_column("[overline white]TAKE", style="white", no_wrap=True)
table.add_column(
"[overline white]NOMINATOR/(24h)/k\u03C4", style="green", justify="center"
f"[overline white]NOMINATOR/(24h)/k{cwtensor.giga_token_symbol}", style="green", justify="center"
)
table.add_column("[overline white]DELEGATE/(24h)", style="green", justify="center")
table.add_column("[overline white]Desc", style="rgb(50,163,219)")
Expand Down Expand Up @@ -259,7 +259,7 @@ def run(cli):
"""Delegates stake to a chain delegate."""
config = cli.config.copy()
wallet = cybertensor.wallet(config=config)
cwtensor: cybertensor.cwtensor = cybertensor.cwtensor(config=config)
cwtensor = cybertensor.cwtensor(config=config)
cwtensor.delegate(
wallet=wallet,
delegate=config.get("delegatekey"),
Expand All @@ -279,7 +279,7 @@ def add_args(parser: argparse.ArgumentParser):
dest="delegatekey",
type=str,
required=False,
help="""The address of the choosen delegate""",
help="""The address of the chosen delegate""",
)
delegate_stake_parser.add_argument(
"--all", dest="stake_all", action="store_true"
Expand Down Expand Up @@ -311,9 +311,7 @@ def check_config(config: "cybertensor.config"):

if len(delegates) == 0:
console.print(
":cross_mark: [red]There are no delegates on {}[/red]".format(
cwtensor.network
)
f":cross_mark: [red]There are no delegates on {cwtensor.network}[/red]"
)
sys.exit(1)

Expand All @@ -332,18 +330,16 @@ def check_config(config: "cybertensor.config"):
# Get amount.
if not config.get("amount") and not config.get("stake_all"):
if not Confirm.ask(
"Stake all GBOOT from account: [bold]'{}'[/bold]?".format(
config.wallet.get("name", defaults.wallet.name)
)
f"Stake all {cwtensor.giga_token_symbol} "
f"from account: [bold]'{config.wallet.get('name', defaults.wallet.name)}'[/bold]?"
):
amount = Prompt.ask("Enter GBOOT amount to stake")
amount = Prompt.ask(f"Enter {cwtensor.giga_token_symbol} amount to stake")
try:
config.amount = float(amount)
except ValueError:
console.print(
":cross_mark: [red]Invalid GBOOT amount[/red] [bold white]{}[/bold white]".format(
amount
)
f":cross_mark: [red]Invalid {cwtensor.giga_token_symbol} amount[/red] "
f"[bold white]{amount}[/bold white]"
)
sys.exit()
else:
Expand Down Expand Up @@ -387,7 +383,7 @@ def run(cli):
"""Undelegates stake from a chain delegate."""
config = cli.config.copy()
wallet = cybertensor.wallet(config=config)
cwtensor: cybertensor.cwtensor = cybertensor.cwtensor(config=config)
cwtensor = cybertensor.cwtensor(config=config)
cwtensor.undelegate(
wallet=wallet,
delegate=config.get("delegatekey"),
Expand Down Expand Up @@ -443,35 +439,29 @@ def check_config(config: "cybertensor.config"):

if len(delegates) == 0:
console.print(
":cross_mark: [red]There are no delegates on {}[/red]".format(
cwtensor.network
)
f":cross_mark: [red]There are no delegates on {cwtensor.network}[/red]"
)
sys.exit(1)

delegates.sort(key=lambda delegate: delegate.total_stake, reverse=True)
show_delegates(config, delegates, prev_delegates=prev_delegates)
delegate_index = Prompt.ask("Enter delegate index")
config.delegatekey = str(delegates[int(delegate_index)].hotkey)
console.print(
"Selected: [yellow]{}[/yellow]".format(config.delegatekey)
)
console.print(f"Selected: [yellow]{config.delegatekey}[/yellow]")

# Get amount.
if not config.get("amount") and not config.get("unstake_all"):
if not Confirm.ask(
"Unstake all GBOOT to account: [bold]'{}'[/bold]?".format(
config.wallet.get("name", defaults.wallet.name)
)
f"Unstake all {cwtensor.giga_token_symbol} "
f"to account: [bold]'{config.wallet.get('name', defaults.wallet.name)}'[/bold]?"
):
amount = Prompt.ask("Enter GBOOT amount to unstake")
amount = Prompt.ask(f"Enter {cwtensor.giga_token_symbol} amount to unstake")
try:
config.amount = float(amount)
except ValueError:
console.print(
":cross_mark: [red]Invalid GBOOT amount[/red] [bold white]{}[/bold white]".format(
amount
)
f":cross_mark: [red]Invalid {cwtensor.giga_token_symbol} amount[/red] "
f"[bold white]{amount}[/bold white]"
)
sys.exit()
else:
Expand Down Expand Up @@ -699,7 +689,7 @@ def run(cli):
wallets = _get_coldkey_wallets_for_path(config.wallet.path)
else:
wallets = [cybertensor.wallet(config=config)]
cwtensor: cybertensor.cwtensor = cybertensor.cwtensor(config=config)
cwtensor = cybertensor.cwtensor(config=config)

table = Table(show_footer=True, pad_edge=False, box=None, expand=True)
table.add_column(
Expand All @@ -720,18 +710,18 @@ def run(cli):
style="bold green",
)
table.add_column(
"[overline green]\u03C4/24h",
f"[overline green]{cwtensor.giga_token_symbol}/24h",
footer_style="overline green",
style="bold green",
)
table.add_column(
"[overline white]NOMS", justify="center", style="green", no_wrap=True
)
table.add_column(
"[overline white]OWNER STAKE(\u03C4)", justify="right", no_wrap=True
f"[overline white]OWNER STAKE({cwtensor.giga_token_symbol})", justify="right", no_wrap=True
)
table.add_column(
"[overline white]TOTAL STAKE(\u03C4)",
f"[overline white]TOTAL STAKE({cwtensor.giga_token_symbol})",
justify="right",
style="green",
no_wrap=True,
Expand All @@ -740,7 +730,7 @@ def run(cli):
"[overline white]SUBNETS", justify="right", style="white", no_wrap=True
)
table.add_column("[overline white]VPERMIT", justify="right", no_wrap=True)
table.add_column("[overline white]24h/k\u03C4", style="green", justify="center")
table.add_column(f"[overline white]24h/k{cwtensor.giga_token_symbol}", style="green", justify="center")
table.add_column("[overline white]Desc", style="rgb(50,163,219)")
total_delegated = 0

Expand Down Expand Up @@ -826,7 +816,7 @@ def run(cli):
)

cybertensor.__console__.print(table)
cybertensor.__console__.print("Total delegated GBOOT: {}".format(total_delegated))
cybertensor.__console__.print(f"Total delegated {cwtensor.giga_token_symbol}: {total_delegated}")

@staticmethod
def add_args(parser: argparse.ArgumentParser):
Expand Down
Loading

0 comments on commit 383a6ed

Please sign in to comment.