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

Release/8.4.0 #254

Merged
merged 26 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9d07839
Backmerge main to staging (#242)
thewhaleking Nov 13, 2024
88f645d
Uses a more general-use hex_to_bytes function for converting rather t…
thewhaleking Nov 14, 2024
6ca679b
Merge pull request #244 from opentensor/feat/thewhaleking/use-hex-to-…
thewhaleking Nov 14, 2024
d65ca59
Upgrade websockets
thewhaleking Nov 22, 2024
4e5c3cb
Better-improved the asyncio websocket connection.
thewhaleking Nov 22, 2024
c79a816
Synced with bittensor implementation.
thewhaleking Nov 22, 2024
8932194
Remove is_flag and flag_value deprecated Typer args
thewhaleking Nov 22, 2024
fb51ae8
Merge pull request #248 from opentensor/fix/thewhaleking/remove-depre…
ibraheem-opentensor Nov 22, 2024
e07b330
Merge pull request #247 from opentensor/feat/thewhaleking/upgrade-web…
ibraheem-opentensor Nov 25, 2024
63917ab
Speed up faucet (#245)
thewhaleking Nov 25, 2024
086dda5
Fixed overview message descripancy
ibraheem-opentensor Nov 25, 2024
233fd05
Merge pull request #251 from opentensor/fix/overview-warning
ibraheem-opentensor Nov 26, 2024
31adc4c
Fix hyperparams setting. (#252)
thewhaleking Nov 26, 2024
e7b9122
Bumps version and updates changelog
ibraheem-opentensor Nov 26, 2024
d01bf8a
Merge branch 'main' into backmerge/main-staging-840
ibraheem-opentensor Nov 26, 2024
639777b
Merge pull request #253 from opentensor/backmerge/main-staging-840
ibraheem-opentensor Nov 26, 2024
a82e64c
Merge branch 'staging' into release/8.4.0
ibraheem-opentensor Nov 26, 2024
36179ce
Updates changelog
ibraheem-opentensor Nov 26, 2024
3eef3b6
Bumps btwallet to 2.1.2
ibraheem-opentensor Nov 27, 2024
41dd6a7
Merge pull request #255 from opentensor/update-btwallet-212
ibraheem-opentensor Nov 27, 2024
3e93cb2
Merge branch 'staging' into release/8.4.0
ibraheem-opentensor Nov 27, 2024
4bf0686
Updates changelog
ibraheem-opentensor Nov 27, 2024
9dd967c
Bumps btwallet to 2.1.3
ibraheem-opentensor Nov 27, 2024
3f4b5db
Merge pull request #256 from opentensor/update-btwallet-213
ibraheem-opentensor Nov 27, 2024
eed192f
Merge branch 'staging' into release/8.4.0
ibraheem-opentensor Nov 27, 2024
c60f571
Updates changelog
ibraheem-opentensor Nov 27, 2024
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 8.4.0 /2024-11-27

## What's Changed
* Use hex to bytes function by @thewhaleking in https://github.com/opentensor/btcli/pull/244
* Remove deprecated Typer options by @thewhaleking in https://github.com/opentensor/btcli/pull/248
* Upgrade websockets by @thewhaleking in https://github.com/opentensor/btcli/pull/247
* Fast block improvements by @thewhaleking in https://github.com/opentensor/btcli/pull/245
* Fixed overview message discrepancy by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/251
* Fix hyperparams setting. by @thewhaleking in https://github.com/opentensor/btcli/pull/252
* Bumps btwallet to 2.1.2 by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/255
* Bumps btwallet to 2.1.3 by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/256

**Full Changelog**: https://github.com/opentensor/btcli/compare/v8.3.1...v8.4.0

## 8.3.1 /2024-11-13

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion bittensor_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
from .cli import CLIManager


__version__ = "8.3.1"
__version__ = "8.4.0"

__all__ = ["CLIManager", "__version__"]
18 changes: 11 additions & 7 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class GitError(Exception):
pass


__version__ = "8.3.1"
__version__ = "8.4.0"


_core_version = re.match(r"^\d+\.\d+\.\d+", __version__).group(0)
Expand Down Expand Up @@ -127,8 +127,6 @@ class Options:
use_password = typer.Option(
True,
help="Set this to `True` to protect the generated Bittensor key with a password.",
is_flag=True,
flag_value=False,
)
public_hex_key = typer.Option(None, help="The public key in hex format.")
ss58_address = typer.Option(
Expand Down Expand Up @@ -1843,8 +1841,6 @@ def wallet_regen_hotkey(
use_password: bool = typer.Option(
False, # Overriden to False
help="Set to 'True' to protect the generated Bittensor key with a password.",
is_flag=True,
flag_value=True,
),
quiet: bool = Options.quiet,
verbose: bool = Options.verbose,
Expand Down Expand Up @@ -1901,8 +1897,6 @@ def wallet_new_hotkey(
use_password: bool = typer.Option(
False, # Overriden to False
help="Set to 'True' to protect the generated Bittensor key with a password.",
is_flag=True,
flag_value=True,
),
quiet: bool = Options.quiet,
verbose: bool = Options.verbose,
Expand Down Expand Up @@ -3910,6 +3904,16 @@ def sudo_set(
)
param_name = hyperparam_list[choice - 1]

if param_name in ["alpha_high", "alpha_low"]:
param_name = "alpha_values"
low_val = FloatPrompt.ask(
"Enter the new value for [dark_orange]alpha_low[/dark_orange]"
)
high_val = FloatPrompt.ask(
"Enter the new value for [dark_orange]alpha_high[/dark_orange]"
)
param_value = f"{low_val},{high_val}"

if not param_value:
param_value = Prompt.ask(
f"Enter the new value for [dark_orange]{param_name}[/dark_orange] in the VALUE column format"
Expand Down
22 changes: 13 additions & 9 deletions bittensor_cli/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,28 +318,32 @@ class WalletValidationTypes(Enum):


HYPERPARAMS = {
"serving_rate_limit": "sudo_set_serving_rate_limit",
"rho": "sudo_set_rho",
"kappa": "sudo_set_kappa",
"immunity_period": "sudo_set_immunity_period",
"min_allowed_weights": "sudo_set_min_allowed_weights",
"max_weights_limit": "sudo_set_max_weight_limit",
"tempo": "sudo_set_tempo",
"min_difficulty": "sudo_set_min_difficulty",
"max_difficulty": "sudo_set_max_difficulty",
"weights_version": "sudo_set_weights_version_key",
"weights_rate_limit": "sudo_set_weights_set_rate_limit",
"max_weight_limit": "sudo_set_max_weight_limit",
"immunity_period": "sudo_set_immunity_period",
"min_allowed_weights": "sudo_set_min_allowed_weights",
"adjustment_interval": "sudo_set_adjustment_interval",
"activity_cutoff": "sudo_set_activity_cutoff",
"network_registration_allowed": "sudo_set_network_registration_allowed",
"network_pow_registration_allowed": "sudo_set_network_pow_registration_allowed",
"target_regs_per_interval": "sudo_set_target_registrations_per_interval",
"min_burn": "sudo_set_min_burn",
"max_burn": "sudo_set_max_burn",
"bonds_moving_avg": "sudo_set_bonds_moving_average",
"max_regs_per_block": "sudo_set_max_registrations_per_block",
"serving_rate_limit": "sudo_set_serving_rate_limit",
"max_validators": "sudo_set_max_allowed_validators",
"adjustment_alpha": "sudo_set_adjustment_alpha",
"rho": "sudo_set_rho",
"kappa": "sudo_set_kappa",
"difficulty": "sudo_set_difficulty",
"bonds_moving_avg": "sudo_set_bonds_moving_average",
"commit_reveal_weights_interval": "sudo_set_commit_reveal_weights_interval",
"commit_reveal_weights_enabled": "sudo_set_commit_reveal_weights_enabled",
"alpha_values": "sudo_set_alpha_values",
"liquid_alpha_enabled": "sudo_set_liquid_alpha_enabled",
"registration_allowed": "sudo_set_network_registration_allowed",
}

# Help Panels for cli help
Expand Down
64 changes: 29 additions & 35 deletions bittensor_cli/src/bittensor/async_substrate_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
from collections import defaultdict
from dataclasses import dataclass
from hashlib import blake2b
from typing import Optional, Any, Union, Callable, Awaitable, cast
from typing import Optional, Any, Union, Callable, Awaitable, cast, TYPE_CHECKING

from async_property import async_property
from bt_decode import PortableRegistry, decode as decode_by_type_string, MetadataV15
from bittensor_wallet import Keypair
from packaging import version
from scalecodec import GenericExtrinsic
from scalecodec.base import ScaleBytes, ScaleType, RuntimeConfigurationObject
from scalecodec.type_registry import load_type_registry_preset
Expand All @@ -20,7 +19,13 @@
BlockNotFound,
)
from substrateinterface.storage import StorageKey
import websockets
from websockets.asyncio.client import connect
from websockets.exceptions import ConnectionClosed

from bittensor_cli.src.bittensor.utils import hex_to_bytes

if TYPE_CHECKING:
from websockets.asyncio.client import ClientConnection

ResultHandler = Callable[[dict, Any], Awaitable[tuple[dict, bool]]]

Expand Down Expand Up @@ -434,7 +439,7 @@ def add_item(
self.block_hashes[block_hash] = runtime

def retrieve(
self, block: Optional[int], block_hash: Optional[str]
self, block: Optional[int] = None, block_hash: Optional[str] = None
) -> Optional["Runtime"]:
if block is not None:
return self.blocks.get(block)
Expand Down Expand Up @@ -625,7 +630,7 @@ def __init__(
# TODO allow setting max concurrent connections and rpc subscriptions per connection
# TODO reconnection logic
self.ws_url = ws_url
self.ws: Optional[websockets.WebSocketClientProtocol] = None
self.ws: Optional["ClientConnection"] = None
self.id = 0
self.max_subscriptions = max_subscriptions
self.max_connections = max_connections
Expand All @@ -647,15 +652,12 @@ async def __aenter__(self):
self._exit_task.cancel()
if not self._initialized:
self._initialized = True
await self._connect()
self.ws = await asyncio.wait_for(
connect(self.ws_url, **self._options), timeout=10
)
self._receiving_task = asyncio.create_task(self._start_receiving())
return self

async def _connect(self):
self.ws = await asyncio.wait_for(
websockets.connect(self.ws_url, **self._options), timeout=10
)

async def __aexit__(self, exc_type, exc_val, exc_tb):
async with self._lock:
self._in_use -= 1
Expand Down Expand Up @@ -696,9 +698,7 @@ async def shutdown(self):

async def _recv(self) -> None:
try:
response = json.loads(
await cast(websockets.WebSocketClientProtocol, self.ws).recv()
)
response = json.loads(await self.ws.recv())
async with self._lock:
self._open_subscriptions -= 1
if "id" in response:
Expand All @@ -707,7 +707,7 @@ async def _recv(self) -> None:
self._received[response["params"]["subscription"]] = response
else:
raise KeyError(response)
except websockets.ConnectionClosed:
except ConnectionClosed:
raise
except KeyError as e:
raise e
Expand All @@ -718,7 +718,7 @@ async def _start_receiving(self):
await self._recv()
except asyncio.CancelledError:
pass
except websockets.ConnectionClosed:
except ConnectionClosed:
# TODO try reconnect, but only if it's needed
raise

Expand All @@ -735,7 +735,7 @@ async def send(self, payload: dict) -> int:
try:
await self.ws.send(json.dumps({**payload, **{"id": original_id}}))
return original_id
except websockets.ConnectionClosed:
except ConnectionClosed:
raise

async def retrieve(self, item_id: int) -> Optional[dict]:
Expand Down Expand Up @@ -772,13 +772,13 @@ def __init__(
"""
self.chain_endpoint = chain_endpoint
self.__chain = chain_name
options = {
"max_size": 2**32,
"write_limit": 2**16,
}
if version.parse(websockets.__version__) < version.parse("14.0"):
options.update({"read_limit": 2**16})
self.ws = Websocket(chain_endpoint, options=options)
self.ws = Websocket(
chain_endpoint,
options={
"max_size": 2**32,
"write_limit": 2**16,
},
)
self._lock = asyncio.Lock()
self.last_block_hash: Optional[str] = None
self.config = {
Expand Down Expand Up @@ -1135,7 +1135,7 @@ async def create_storage_key(
-------
StorageKey
"""
runtime = await self.init_runtime(block_hash=block_hash)
await self.init_runtime(block_hash=block_hash)

return StorageKey.create_from_storage_function(
pallet,
Expand Down Expand Up @@ -1555,7 +1555,7 @@ async def _process_response(
self,
response: dict,
subscription_id: Union[int, str],
value_scale_type: Optional[str],
value_scale_type: Optional[str] = None,
storage_item: Optional[ScaleType] = None,
runtime: Optional[Runtime] = None,
result_handler: Optional[ResultHandler] = None,
Expand Down Expand Up @@ -1769,7 +1769,6 @@ async def compose_call(
call_params = {}

await self.init_runtime(block_hash=block_hash)

call = self.runtime_config.create_scale_object(
type_string="Call", metadata=self.metadata
)
Expand Down Expand Up @@ -2087,7 +2086,8 @@ async def create_signed_extrinsic(

:return: The signed Extrinsic
"""
await self.init_runtime()
if not self.metadata:
await self.init_runtime()

# Check requirements
if not isinstance(call, GenericCall):
Expand Down Expand Up @@ -2140,7 +2140,6 @@ async def create_signed_extrinsic(
extrinsic = self.runtime_config.create_scale_object(
type_string="Extrinsic", metadata=self.metadata
)

value = {
"account_id": f"0x{keypair.public_key.hex()}",
"signature": f"0x{signature.hex()}",
Expand All @@ -2158,9 +2157,7 @@ async def create_signed_extrinsic(
signature_cls = self.runtime_config.get_decoder_class("ExtrinsicSignature")
if issubclass(signature_cls, self.runtime_config.get_decoder_class("Enum")):
value["signature_version"] = signature_version

extrinsic.encode(value)

return extrinsic

async def get_chain_finalised_head(self):
Expand Down Expand Up @@ -2564,10 +2561,7 @@ def concat_hash_len(key_hasher: str) -> int:
item_key = None

try:
try:
item_bytes = bytes.fromhex(item[1][2:])
except ValueError:
item_bytes = bytes.fromhex(item[1])
item_bytes = hex_to_bytes(item[1])

item_value = await self.decode_scale(
type_string=value_type,
Expand Down
Loading
Loading