Skip to content

Commit

Permalink
Merge pull request #1365 from opentensor/release/5.1.0
Browse files Browse the repository at this point in the history
Release/5.1.0
  • Loading branch information
ifrit98 committed Jun 1, 2023
2 parents 5241134 + 3baa2b6 commit a99ce78
Show file tree
Hide file tree
Showing 95 changed files with 3,975 additions and 1,047 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
**/env/*
**/venv/*
./circleci/*
./github/*
./github/*
.ipynb
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 5.1.0 / 2023-05-30

## What's Changed
* update readme by @unconst in https://github.com/opentensor/bittensor/pull/1344
* Reset scores for validators by @adriansmares in https://github.com/opentensor/bittensor/pull/1359


**Full Changelog**: https://github.com/opentensor/bittensor/compare/v5.0.0...v5.1.0


## 5.0.0 / 2023-05-17

**Full Changelog**: https://github.com/opentensor/bittensor/compare/v4.0.1...v5.0.0
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.0
5.1.0
9 changes: 7 additions & 2 deletions bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
nest_asyncio.apply()

# Bittensor code and protocol version.
__version__ = '5.0.0'
__version__ = '5.1.0'
version_split = __version__.split(".")
__version_as_int__ = (100 * int(version_split[0])) + (10 * int(version_split[1])) + (1 * int(version_split[2]))
__new_signature_version__ = 360
Expand Down Expand Up @@ -168,6 +168,8 @@ def turn_console_off():
from bittensor._serializer import serializer as serializer
from bittensor._dataset import dataset as dataset
from bittensor._threadpool import prioritythreadpool as prioritythreadpool
from bittensor._blacklist import blacklist as blacklist
from bittensor._priority import priority as priority

# ---- Classes -----
from bittensor._cli.cli_impl import CLI as CLI
Expand Down Expand Up @@ -207,7 +209,10 @@ def turn_console_off():
from bittensor._dendrite.text_prompting.dendrite_pool import TextPromptingDendritePool as text_prompting_pool

# ---- Base Miners -----
from bittensor._synapse.text_prompting.miner import BasePromptingMiner
from bittensor._neuron.base_miner_neuron import BaseMinerNeuron
from bittensor._neuron.base_validator import BaseValidator
from bittensor._neuron.base_prompting_miner import BasePromptingMiner
from bittensor._neuron.base_huggingface_miner import HuggingFaceMiner

# ---- Errors and Exceptions -----
from bittensor._keyfile.keyfile_impl import KeyFileError as KeyFileError
Expand Down
15 changes: 10 additions & 5 deletions bittensor/_axon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def info(self) -> 'axon_info':
def __init__(
self,
wallet: "bittensor.Wallet",
metagraph: "bittensor.Metagraph",
metagraph: Optional["bittensor.Metagraph"] = None,
config: Optional["bittensor.config"] = None,
port: Optional[int] = None,
ip: Optional[str] = None,
Expand Down Expand Up @@ -159,6 +159,11 @@ def help(cls):
def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None):
"""Accept specific arguments from parser"""
prefix_str = "" if prefix is None else prefix + "."
if prefix is not None:
if not hasattr(bittensor.defaults, prefix):
setattr(bittensor.defaults, prefix, bittensor.Config())
getattr(bittensor.defaults, prefix).axon = bittensor.defaults.axon

bittensor.prioritythreadpool.add_args(parser, prefix=prefix_str + "axon")
try:
parser.add_argument(
Expand Down Expand Up @@ -290,7 +295,7 @@ def __init__(
self.receiver_hotkey = receiver_hotkey


def parse_signature_v2(self, signature: str) -> Union[Tuple[int, str, str, str, int], None]:
def parse_signature_v2(self, signature: str) -> Optional[Tuple[int, str, str, str]]:
r"""Attempts to parse a signature using the v2 format"""
parts = signature.split(".")
if len(parts) != 4:
Expand All @@ -304,7 +309,7 @@ def parse_signature_v2(self, signature: str) -> Union[Tuple[int, str, str, str,
receptor_uuid = parts[3]
return (nonce, sender_hotkey, signature, receptor_uuid)

def parse_signature(self, metadata: Dict[str, str]) -> Tuple[int, str, str, str, int]:
def parse_signature(self, metadata: Dict[str, str]) -> Tuple[int, str, str, str]:
r"""Attempts to parse a signature from the metadata"""
signature = metadata.get("bittensor-signature")
version = metadata.get('bittensor-version')
Expand Down Expand Up @@ -444,7 +449,7 @@ def to_parameter_dict( self ) -> 'torch.nn.ParameterDict':
)

@classmethod
def from_parameter_dict( cls, parameter_dict: 'torch.nn.ParameterDict' ) -> 'SubnetInfo':
r""" Returns a SubnetInfo object from a torch parameter_dict.
def from_parameter_dict( cls, parameter_dict: 'torch.nn.ParameterDict' ) -> 'axon_info':
r""" Returns an axon_info object from a torch parameter_dict.
"""
return cls( **dict(parameter_dict) )
114 changes: 114 additions & 0 deletions bittensor/_blacklist/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2022 Opentensor Foundation

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.

# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import argparse
import bittensor
from typing import Union, Tuple

class blacklist:

def __init__( self, config: "bittensor.Config" = None ):
self.config = config or blacklist.config()

@classmethod
def config( cls ) -> "bittensor.Config":
parser = argparse.ArgumentParser()
blacklist.add_args(parser)
return bittensor.config( parser )

@classmethod
def help(cls):
parser = argparse.ArgumentParser()
cls.add_args(parser)
print( cls.__new__.__doc__ )
parser.print_help()

@classmethod
def add_args( cls, parser: argparse.ArgumentParser, prefix: str = None ):
prefix_str = "" if prefix is None else prefix + "."
parser.add_argument(
'--' + prefix_str + 'blacklist.blacklisted_keys',
type = str,
required = False,
nargs = '*',
action = 'store',
help = 'List of ss58 addresses which are always disallowed pass through.', default=[]
)
parser.add_argument(
'--' + prefix_str + 'blacklist.whitelisted_keys',
type = str,
required = False,
nargs = '*',
action = 'store',
help = 'List of ss58 addresses which are always allowed pass through.', default=[]
)
parser.add_argument(
'--' + prefix_str + 'blacklist.allow_non_registered',
action = 'store_true',
help = 'If True, the miner will allow non-registered hotkeys to mine.',
default = True
)
parser.add_argument(
'--' + prefix_str + 'blacklist.min_allowed_stake',
type = float,
help = 'Minimum stake required to pass blacklist.',
default = 0.0
)
parser.add_argument(
'--' + prefix_str + 'blacklist.vpermit_required',
action = 'store_true',
help = 'If True, the miner will require a vpermit to pass blacklist.',
default = False
)

def blacklist(
self,
forward_call: "bittensor.SynapseCall",
metagraph: "bittensor.Metagraph" = None,
) -> Union[ Tuple[bool, str], bool ]:

# Check for blacklisted keys which take priority over all other checks.
src_hotkey = forward_call.src_hotkey
if src_hotkey in self.config.blacklist.blacklisted_keys:
return True, 'blacklisted key'

# Check for whitelisted keys which take priority over all remaining checks.
if src_hotkey in self.config.blacklist.whitelisted_keys:
return False, 'whitelisted key'

# Check if pubkey is registered.
is_registered = False
if metagraph is not None:
is_registered = src_hotkey in metagraph.hotkeys

if not is_registered and not self.config.blacklist.allow_non_registered:
return True, 'pubkey not registered'

# Check for stake amount.
if is_registered and self.config.blacklist.min_allowed_stake > 0.0:
uid = metagraph.hotkeys.index(src_hotkey)
stake = metagraph.S[uid].item()
if stake < self.config.blacklist.min_allowed_stake:
return True, 'pubkey stake below min_allowed_stake'

# Check for vpermit.
if metagraph is not None and self.config.blacklist.vpermit_required and is_registered:
uid = metagraph.hotkeys.index(src_hotkey)
return metagraph.neurons[uid].validator_permit

# All checks passed.
return False, 'passed blacklist'
13 changes: 5 additions & 8 deletions bittensor/_cli/commands/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def check_config( config: 'bittensor.Config' ):
config.delegate_ss58key = str(delegates[int(delegate_index)].hotkey_ss58)
console.print("Selected: [yellow]{}[/yellow]".format(config.delegate_ss58key))

if config.wallet.get('name') == bittensor.defaults.wallet.name and not config.no_prompt:
if not config.is_set('wallet.name') and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

Expand Down Expand Up @@ -281,10 +281,7 @@ def add_args( parser: argparse.ArgumentParser ):

@staticmethod
def check_config( config: 'bittensor.Config' ):
# if config.subtensor.get('network') == bittensor.defaults.subtensor.network and not config.no_prompt:
# config.subtensor.network = Prompt.ask("Enter subtensor network", choices=bittensor.__networks__, default = bittensor.defaults.subtensor.network)

if config.wallet.get('name') == bittensor.defaults.wallet.name and not config.no_prompt:
if not config.is_set('wallet.name') and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

Expand Down Expand Up @@ -410,11 +407,11 @@ def add_args( parser: argparse.ArgumentParser ):

@staticmethod
def check_config( config: 'bittensor.Config' ):
if config.wallet.get('name') == bittensor.defaults.wallet.name and not config.no_prompt:
if not config.is_set('wallet.name') and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

if config.wallet.get('hotkey') == bittensor.defaults.wallet.hotkey and not config.no_prompt:
if not config.is_set('wallet.hotkey') and not config.no_prompt:
hotkey = Prompt.ask("Enter hotkey name", default = bittensor.defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)

Expand Down Expand Up @@ -527,7 +524,7 @@ def add_args( parser: argparse.ArgumentParser ):

@staticmethod
def check_config( config: 'bittensor.Config' ):
if not config.get( 'all', d=None ) and config.wallet.get('name') == bittensor.defaults.wallet.name and not config.no_prompt:
if not config.get( 'all', d=None ) and not config.is_set('wallet.name') and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

Expand Down
14 changes: 12 additions & 2 deletions bittensor/_cli/commands/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,24 @@ def run (cli):
for netuid in netuids:
for neuron in neuron_state_dict[netuid]:
if neuron.coldkey == wallet.coldkeypub.ss58_address:
hotkey_name: str = ''

hotkey_names: List[str] = \
[ wallet.hotkey_str for wallet in filter(
lambda hotkey: hotkey.hotkey.ss58_address == neuron.hotkey,
hotkeys
) ]
if len(hotkey_names) > 0:
hotkey_name = f'{hotkey_names[0]}-'

table.add_row(
'',
'',
'',
'',
'',
str( netuid ),
str( neuron.hotkey ),
f'{hotkey_name}{neuron.hotkey}',
str( neuron.stake ),
str( bittensor.Balance.from_tao(neuron.emission) )
)
Expand All @@ -139,7 +149,7 @@ def run (cli):

@staticmethod
def check_config( config: 'bittensor.Config' ):
if not config.get( 'all', d=None ) and config.wallet.get('name') == bittensor.defaults.wallet.name and not config.no_prompt:
if not config.get( 'all', d=None ) and not config.is_set('wallet.name') and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

Expand Down
2 changes: 1 addition & 1 deletion bittensor/_cli/commands/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def add_args( parser: argparse.ArgumentParser ):

@staticmethod
def check_config( config: 'bittensor.Config' ):
if config.wallet.get('name') == bittensor.defaults.wallet.name and not config.no_prompt and not config.get( 'all', d=None ):
if not config.is_set('wallet.name') and not config.no_prompt and not config.get( 'all', d=None ):
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

Expand Down
10 changes: 5 additions & 5 deletions bittensor/_cli/commands/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def add_args( parser: argparse.ArgumentParser ):
def check_config( config: 'bittensor.Config' ):
check_netuid_set( config, subtensor = bittensor.subtensor( config = config ) )

if config.wallet.get('name') == bittensor.defaults.wallet.name and not config.no_prompt:
if not config.is_set('wallet.name') and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

if config.wallet.get('hotkey') == bittensor.defaults.wallet.hotkey and not config.no_prompt:
if not config.is_set('wallet.hotkey') and not config.no_prompt:
hotkey = Prompt.ask("Enter hotkey name", default = bittensor.defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)

Expand Down Expand Up @@ -158,15 +158,15 @@ def add_args( parser: argparse.ArgumentParser ):

@staticmethod
def check_config( config: 'bittensor.Config' ):
if config.subtensor.get('network') == bittensor.defaults.subtensor.network and not config.no_prompt:
if not config.is_set('subtensor.network') and not config.no_prompt:
config.subtensor.network = Prompt.ask("Enter subtensor network", choices=bittensor.__networks__, default = bittensor.defaults.subtensor.network)

check_netuid_set( config, subtensor = bittensor.subtensor( config = config ) )

if config.wallet.get('name') == bittensor.defaults.wallet.name and not config.no_prompt:
if not config.is_set('wallet.name') and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

if config.wallet.get('hotkey') == bittensor.defaults.wallet.hotkey and not config.no_prompt:
if not config.is_set('wallet.hotkey') and not config.no_prompt:
hotkey = Prompt.ask("Enter hotkey name", default = bittensor.defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)
4 changes: 2 additions & 2 deletions bittensor/_cli/commands/stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ def run( cli ):

@classmethod
def check_config( cls, config: 'bittensor.Config' ):
if config.wallet.get('name') == bittensor.defaults.wallet.name and not config.no_prompt:
if not config.is_set('wallet.name') and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

if config.wallet.get('hotkey') == bittensor.defaults.wallet.hotkey and not config.no_prompt and not config.get('all_hotkeys') and not config.get('hotkeys'):
if not config.is_set('wallet.hotkey') and not config.no_prompt and not config.wallet.get('all_hotkeys') and not config.wallet.get('hotkeys'):
hotkey = Prompt.ask("Enter hotkey name", default = bittensor.defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)

Expand Down
2 changes: 1 addition & 1 deletion bittensor/_cli/commands/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def run (cli):

@staticmethod
def check_config( config: 'bittensor.Config' ):
if config.wallet.get('name') == bittensor.defaults.wallet.name and not config.no_prompt:
if not config.is_set('wallet.name') and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

Expand Down
8 changes: 4 additions & 4 deletions bittensor/_cli/commands/unstake.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

class UnStakeCommand:

@classmethod
def check_config( cls, config: 'bittensor.Config' ):
if config.wallet.get('name') == bittensor.defaults.wallet.name and not config.no_prompt:
@classmethod
def check_config( cls, config: 'bittensor.Config' ):
if config.is_set('wallet.name') and not config.no_prompt:
wallet_name = Prompt.ask("Enter wallet name", default = bittensor.defaults.wallet.name)
config.wallet.name = str(wallet_name)

if not config.get('hotkey_ss58address') and config.wallet.get('hotkey') == bittensor.defaults.wallet.hotkey and not config.no_prompt and not config.get('all_hotkeys') and not config.get('hotkeys'):
if not config.get( 'hotkey_ss58address', d=None ) and config.is_set('wallet.hotkey') and not config.no_prompt and not config.get('all_hotkeys') and not config.get('hotkeys'):
hotkey = Prompt.ask("Enter hotkey name", default = bittensor.defaults.wallet.hotkey)
config.wallet.hotkey = str(hotkey)

Expand Down
Loading

0 comments on commit a99ce78

Please sign in to comment.