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

Backmerge master -> staging #2136

Merged
merged 1 commit into from
Jul 15, 2024
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
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ jobs:
command: |
./scripts/release/release.sh --github-token ${GH_API_ACCESS_TOKEN}


workflows:
compatibility_checks:
jobs:
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Build and Publish Python Package

on:
workflow_dispatch:
inputs:
version:
description: 'Version to release'
required: true
type: string

jobs:
build:
name: Build Python distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build wheel twine

- name: Build package
run: python setup.py sdist bdist_wheel

- name: Check if package version already exists
run: |
PACKAGE_NAME=$(python setup.py --name)
PACKAGE_VERSION=${{ github.event.inputs.version }}
if twine check dist/*; then
if pip install $PACKAGE_NAME==$PACKAGE_VERSION; then
echo "Error: Version $PACKAGE_VERSION of $PACKAGE_NAME already exists on PyPI"
exit 1
else
echo "Version $PACKAGE_VERSION of $PACKAGE_NAME does not exist on PyPI. Proceeding with upload."
fi
else
echo "Error: Twine check failed."
exit 1
fi

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/

approve-and-publish:
needs: build
runs-on: ubuntu-latest
environment: release
permissions:
contents: read
id-token: write

steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: dist
path: dist/

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
print-hash: true
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 7.3.0 / 2024-07-12

## What's Changed
* Liquid Alpha by @opendansor & @gus-opentensor in https://github.com/opentensor/bittensor/pull/2012
* check_coldkey_swap by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2126

**Full Changelog**: https://github.com/opentensor/bittensor/compare/v7.2.0...v7.3.0


## 7.2.0 / 2024-06-12

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.2.0
7.3.0
33 changes: 32 additions & 1 deletion bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


# Bittensor code and protocol version.
__version__ = "7.2.0"
__version__ = "7.3.0"

_version_split = __version__.split(".")
__version_info__ = tuple(int(part) for part in _version_split)
Expand Down Expand Up @@ -234,6 +234,37 @@ def debug(on: bool = True):
"SubnetRegistrationRuntimeApi": {
"methods": {"get_network_registration_cost": {"params": [], "type": "u64"}}
},
"ColdkeySwapRuntimeApi": {
"methods": {
"get_scheduled_coldkey_swap": {
"params": [
{
"name": "coldkey_account_vec",
"type": "Vec<u8>",
},
],
"type": "Vec<u8>",
},
"get_remaining_arbitration_period": {
"params": [
{
"name": "coldkey_account_vec",
"type": "Vec<u8>",
},
],
"type": "Vec<u8>",
},
"get_coldkey_swap_destinations": {
"params": [
{
"name": "coldkey_account_vec",
"type": "Vec<u8>",
},
],
"type": "Vec<u8>",
},
}
},
},
}

Expand Down
69 changes: 66 additions & 3 deletions bittensor/chain_data.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# The MIT License (MIT)
# Copyright © 2023 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
Expand Down Expand Up @@ -191,6 +191,14 @@
["liquid_alpha_enabled", "bool"],
],
},
"ScheduledColdkeySwapInfo": {
"type": "struct",
"type_mapping": [
["old_coldkey", "AccountId"],
["new_coldkey", "AccountId"],
["arbitration_block", "Compact<u64>"],
],
},
}
}

Expand Down Expand Up @@ -324,6 +332,8 @@ class ChainDataType(Enum):
StakeInfo = 6
IPInfo = 7
SubnetHyperparameters = 8
ScheduledColdkeySwapInfo = 9
AccountId = 10


def from_scale_encoding(
Expand Down Expand Up @@ -1140,3 +1150,56 @@ class ProposalVoteData(TypedDict):


ProposalCallData = GenericCall


@dataclass
class ScheduledColdkeySwapInfo:
"""Dataclass for scheduled coldkey swap information."""

old_coldkey: str
new_coldkey: str
arbitration_block: int

@classmethod
def fix_decoded_values(cls, decoded: Any) -> "ScheduledColdkeySwapInfo":
"""Fixes the decoded values."""
return cls(
old_coldkey=ss58_encode(decoded["old_coldkey"], bittensor.__ss58_format__),
new_coldkey=ss58_encode(decoded["new_coldkey"], bittensor.__ss58_format__),
arbitration_block=decoded["arbitration_block"],
)

@classmethod
def from_vec_u8(cls, vec_u8: List[int]) -> Optional["ScheduledColdkeySwapInfo"]:
"""Returns a ScheduledColdkeySwapInfo object from a ``vec_u8``."""
if len(vec_u8) == 0:
return None

decoded = from_scale_encoding(vec_u8, ChainDataType.ScheduledColdkeySwapInfo)
if decoded is None:
return None

return ScheduledColdkeySwapInfo.fix_decoded_values(decoded)

@classmethod
def list_from_vec_u8(cls, vec_u8: List[int]) -> List["ScheduledColdkeySwapInfo"]:
"""Returns a list of ScheduledColdkeySwapInfo objects from a ``vec_u8``."""
decoded = from_scale_encoding(
vec_u8, ChainDataType.ScheduledColdkeySwapInfo, is_vec=True
)
if decoded is None:
return []

return [ScheduledColdkeySwapInfo.fix_decoded_values(d) for d in decoded]

@classmethod
def decode_account_id_list(cls, vec_u8: List[int]) -> Optional[List[str]]:
"""Decodes a list of AccountIds from vec_u8."""
decoded = from_scale_encoding(
vec_u8, ChainDataType.ScheduledColdkeySwapInfo.AccountId, is_vec=True
)
if decoded is None:
return None
return [
ss58_encode(account_id, bittensor.__ss58_format__) for account_id in decoded
]
2 changes: 2 additions & 0 deletions bittensor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
WalletCreateCommand,
CommitWeightCommand,
RevealWeightCommand,
CheckColdKeySwapCommand,
)

# Create a console instance for CLI display.
Expand Down Expand Up @@ -157,6 +158,7 @@
"set_identity": SetIdentityCommand,
"get_identity": GetIdentityCommand,
"history": GetWalletHistoryCommand,
"check_coldkey_swap": CheckColdKeySwapCommand,
},
},
"stake": {
Expand Down
1 change: 1 addition & 0 deletions bittensor/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,4 @@
RootSetSlashCommand,
)
from .identity import GetIdentityCommand, SetIdentityCommand
from .check_coldkey_swap import CheckColdKeySwapCommand
126 changes: 126 additions & 0 deletions bittensor/commands/check_coldkey_swap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
#
# 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

from rich.prompt import Prompt

import bittensor
from bittensor.utils.formatting import convert_blocks_to_time
from . import defaults

console = bittensor.__console__


def fetch_arbitration_stats(subtensor, wallet):
"""
Performs a check of the current arbitration data (if any), and displays it through the bittensor console.
"""
arbitration_check = len(subtensor.check_in_arbitration(wallet.coldkey.ss58_address))
if arbitration_check == 0:
bittensor.__console__.print(
"[green]There has been no previous key swap initiated for your coldkey.[/green]"
)
if arbitration_check == 1:
arbitration_remaining = subtensor.get_remaining_arbitration_period(
wallet.coldkey.ss58_address
)
hours, minutes, seconds = convert_blocks_to_time(arbitration_remaining)
bittensor.__console__.print(
"[yellow]There has been 1 swap request made for this coldkey already."
" By adding another swap request, the key will enter arbitration."
f" Your key swap is scheduled for {hours} hours, {minutes} minutes, {seconds} seconds"
" from now.[/yellow]"
)
if arbitration_check > 1:
bittensor.__console__.print(
f"[red]This coldkey is currently in arbitration with a total swaps of {arbitration_check}.[/red]"
)


class CheckColdKeySwapCommand:
"""
Executes the ``check_coldkey_swap`` command to check swap status of a coldkey in the Bittensor network.
Usage:
Users need to specify the wallet they want to check the swap status of.
Example usage::
btcli wallet check_coldkey_swap
Note:
This command is important for users who wish check if swap requests were made against their coldkey.
"""

@staticmethod
def run(cli: "bittensor.cli"):
"""
Runs the check coldkey swap command.
Args:
cli (bittensor.cli): The CLI object containing configuration and command-line interface utilities.
"""
try:
config = cli.config.copy()
subtensor: "bittensor.subtensor" = bittensor.subtensor(
config=config, log_verbose=False
)
CheckColdKeySwapCommand._run(cli, subtensor)
except Exception as e:
bittensor.logging.warning(f"Failed to get swap status: {e}")
finally:
if "subtensor" in locals():
subtensor.close()
bittensor.logging.debug("closing subtensor connection")

@staticmethod
def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
"""
Internal method to check coldkey swap status.
Args:
cli (bittensor.cli): The CLI object containing configuration and command-line interface utilities.
subtensor (bittensor.subtensor): The subtensor object for blockchain interactions.
"""
config = cli.config.copy()
wallet = bittensor.wallet(config=config)

fetch_arbitration_stats(subtensor, wallet)

@classmethod
def check_config(cls, config: "bittensor.config"):
"""
Checks and prompts for necessary configuration settings.
Args:
config (bittensor.config): The configuration object.
Prompts the user for wallet name if not set in the config.
"""
if not config.is_set("wallet.name") and not config.no_prompt:
wallet_name: str = Prompt.ask(
"Enter wallet name", default=defaults.wallet.name
)
config.wallet.name = str(wallet_name)

@staticmethod
def add_args(command_parser: argparse.ArgumentParser):
"""
Adds arguments to the command parser.
Args:
command_parser (argparse.ArgumentParser): The command parser to add arguments to.
"""
swap_parser = command_parser.add_parser(
"check_coldkey_swap",
help="""Check the status of swap requests for a coldkey on the Bittensor network.
Adding more than one swap request will make the key go into arbitration mode.""",
)
bittensor.wallet.add_args(swap_parser)
bittensor.subtensor.add_args(swap_parser)
Loading