Skip to content
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
24 changes: 13 additions & 11 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@

## Extrinsics and related
1. ✅ Standardize parameter order across all extrinsics and related calls. Pass extrinsic-specific arguments first (e.g., wallet, hotkey, netuid, amount), followed by optional general flags (e.g., wait_for_inclusion, wait_for_finalization)

2. ✅ Set `wait_for_inclusion` and `wait_for_finalization` to `True` by default in extrinsics and their related calls. Then we will guarantee the correct/expected extrinsic call response is consistent with the chain response. If the user changes those values, then it is the user's responsibility.
3. ✅ Make the internal logic of extrinsics the same. There are extrinsics that are slightly different in implementation.

4. ✅ ~~Since SDK is not a responsible tool, try to remove all calculations inside extrinsics that do not affect the result, but are only used in logging. Actually, this should be applied not to extrinsics only but for all codebase.~~ Just improved regarding usage.

5. ✅ Remove `unstake_all` parameter from `unstake_extrinsic` since we have `unstake_all_extrinsic`which is calles another subtensor function.

6. ✅ `unstake` and `unstake_multiple` extrinsics should have `safe_unstaking` parameters instead of `safe_staking`.

7. ✅ Remove `_do*` extrinsic calls and combine them with extrinsic logic.

8. ✅ ~~`subtensor.get_transfer_fee` calls extrinsic inside the subtensor module. Actually the method could be updated by using `bittensor.core.extrinsics.utils.get_extrinsic_fee`.~~ (`get_transfer_fee` isn't `get_extrinsic_fee`)

## Subtensor
Expand All @@ -35,15 +29,18 @@

## Balance
1. ✅ In `bittensor.utils.balance._check_currencies` raise the error instead of `warnings.warn`.
2. ✅ In `bittensor.utils.balance.check_and_convert_to_balance` raise the error instead of `warnings.warn`.
This may seem like a harsh decision at first, but ultimately we will push the community to use Balance and there will be fewer errors in their calculations. Confusion with TAO and Alpha in calculations and display/printing/logging will be eliminated.
2. ✅ In `bittensor.utils.balance.check_and_convert_to_balance` raise the error instead of `warnings.warn`. This may
seem like a harsh decision at first, but ultimately we will push the community to use Balance and there will be fewer
errors in their calculations. Confusion with TAO and Alpha in calculations and display/printing/logging will be
eliminated.

## Common things
1. ✅ Reduce the amount of logging.info or transfer part of logging.info to logging.debug

2. ✅ To be consistent across all SDK regarding local environment variables name:
remove `BT_CHAIN_ENDPOINT` (settings.py :line 124) and use `BT_SUBTENSOR_CHAIN_ENDPOINT` instead of that.
rename this variable in documentation.
- remove `BT_CHAIN_ENDPOINT` (settings.py :line 124) and use `BT_SUBTENSOR_CHAIN_ENDPOINT` instead of that.
rename this variable in documentation.
- rename local env variable`BT_NETWORK` to `BT_SUBTENSOR_NETWORK`

3. ✅ ~~Move `bittensor.utils.get_transfer_fn_params` to `bittensor.core.extrinsics.utils`.~~ it's on the right place.

Expand All @@ -70,7 +67,7 @@ rename this variable in documentation.
12. ✅ The SDK is dropping support for `Python 3.9` starting with this release.
13. ✅ Remove `Default is` and `Default to` in docstrings bc parameters enough.
14. ✅ `camfairchild`: TODO, but we should have a grab_metadata if we don't already. Maybe don't decode, but can have a call that removes the Raw prefix, and another just doing grab_metadata_raw (no decoding). `get_commitment_metadata` added.
15. Solve the issue when a script using SDK receives the `--config` cli parameter. Disable `argparse` processing by default and enable it only when using SOME? a local environment variable.
15. ✅ Resolve an issue where a script using the SDK receives the `--config` or any other CLI parameters used in the SDK. Disable configuration processing. Use default values ​​instead.
16. Find and process all `TODOs` across the entire code base. If in doubt, discuss each one with the team separately. SDK has 29 TODOs.

## New features
Expand Down Expand Up @@ -322,3 +319,8 @@ Currently it contains:
- [x] `check_and_convert_to_balance` renamed to `check_balance_amount`
- [x] `check_balance_amount` raised `BalanceTypeError` error instead of deprecated warning message.
- [x] private function `bittensor.utils.balance._check_currencies` raises `BalanceUnitMismatchError` error instead of deprecated warning message. This function is used inside the Balance class to check if units match during various mathematical and logical operations.


### ArgParser issue
- to turn on args parser across SDK, the local env variable `BT_PARSE_CLI_ARGS` should be set to on of the values: `1`, `true`, `yes`, `on`.
- `bittensor.core.config.DefaultConfig` class has been deleted (unused).
39 changes: 22 additions & 17 deletions bittensor/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import os
import sys
from copy import deepcopy
from typing import Any, TypeVar, Type, Optional

from typing import Any, Optional
from bittensor.core.settings import DEFAULTS
import yaml
from munch import DefaultMunch

Expand Down Expand Up @@ -51,12 +51,29 @@ def __init__(
parser: argparse.ArgumentParser = None,
args: Optional[list[str]] = None,
strict: bool = False,
default: Any = None,
default: Any = DEFAULTS,
) -> None:
super().__init__(default)
no_parse_cli = os.getenv("BT_NO_PARSE_CLI_ARGS", "").lower() in (
"1",
"true",
"yes",
"on",
)

# Fallback to defaults if not provided
default = deepcopy(default or DEFAULTS)

if isinstance(default, DefaultMunch):
# Initialize Munch with defaults (dict-safe)
super().__init__(None, default.toDict())
else:
# if defaults passed as dict
super().__init__(None, default)

self.__is_set = {}

if parser is None:
# If CLI parsing disabled, stop here
if no_parse_cli or parser is None:
return

self._add_default_arguments(parser)
Expand Down Expand Up @@ -234,15 +251,3 @@ def _add_default_arguments(self, parser: argparse.ArgumentParser) -> None:
except argparse.ArgumentError:
# this can fail if argument has already been added.
pass


T = TypeVar("T", bound="DefaultConfig")


class DefaultConfig(Config):
"""A Config with a set of default values."""

@classmethod
def default(cls: Type[T]) -> T:
"""Get default config."""
raise NotImplementedError("Function default is not implemented.")
5 changes: 4 additions & 1 deletion bittensor/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,17 @@
"subtensor": {
"chain_endpoint": os.getenv("BT_SUBTENSOR_CHAIN_ENDPOINT")
or DEFAULT_ENDPOINT,
"network": os.getenv("BT_NETWORK") or DEFAULT_NETWORK,
"network": os.getenv("BT_SUBTENSOR_NETWORK") or DEFAULT_NETWORK,
"_mock": False,
},
"wallet": {
"name": os.getenv("BT_WALLET_NAME") or "default",
"hotkey": os.getenv("BT_WALLET_HOTKEY") or "default",
"path": os.getenv("BT_WALLET_PATH") or str(WALLETS_DIR),
},
"config": False,
"strict": False,
"no_version_checking": False,
}
)

Expand Down
23 changes: 16 additions & 7 deletions tests/e2e_tests/test_commit_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def test_commit_weights_uses_next_nonce(subtensor, alice_wallet):
Raises:
AssertionError: If any of the checks or verifications fail
"""
TEMPO_TO_SET = 50 if subtensor.chain.is_fast_blocks() else 20
TEMPO_TO_SET = 100 if subtensor.chain.is_fast_blocks() else 20

# Create and prepare subnet
alice_sn = TestSubnet(subtensor)
Expand Down Expand Up @@ -422,7 +422,7 @@ async def test_commit_weights_uses_next_nonce_async(async_subtensor, alice_walle
Raises:
AssertionError: If any of the checks or verifications fail
"""
TEMPO_TO_SET = 50 if await async_subtensor.chain.is_fast_blocks() else 20
TEMPO_TO_SET = 100 if await async_subtensor.chain.is_fast_blocks() else 20

# Create and prepare subnet
alice_sn = TestSubnet(async_subtensor)
Expand Down Expand Up @@ -555,12 +555,21 @@ async def send_commit_():
)
await async_subtensor.wait_for_block(waiting_block)

weight_commits = None
counter = 0
# Query the WeightCommits storage map for all three salts
weight_commits = await async_subtensor.queries.query_module(
module="SubtensorModule",
name="WeightCommits",
params=[alice_sn.netuid, alice_wallet.hotkey.ss58_address],
)
while not weight_commits or not len(weight_commits) == AMOUNT_OF_COMMIT_WEIGHTS:
weight_commits = await async_subtensor.queries.query_module(
module="SubtensorModule",
name="WeightCommits",
params=[alice_sn.netuid, alice_wallet.hotkey.ss58_address],
)
await async_subtensor.wait_for_block()
logging.console.info(f"len(weight_commits): {len(weight_commits)}")
counter += 1
if counter > TEMPO_TO_SET:
break

# Assert that the committed weights are set correctly
assert weight_commits.value is not None, "Weight commit not found in storage"
commit_hash, commit_block, reveal_block, expire_block = weight_commits.value[0]
Expand Down
51 changes: 51 additions & 0 deletions tests/integration_tests/test_config_does_not_process_cli_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import argparse
import sys

import pytest

import bittensor as bt
from bittensor.core.config import InvalidConfigFile


def _config_call():
"""Create a config object from the bt cli args."""
parser = argparse.ArgumentParser()
bt.Axon.add_args(parser)
bt.Subtensor.add_args(parser)
bt.AsyncSubtensor.add_args(parser)
bt.Wallet.add_args(parser)
bt.logging.add_args(parser)
bt.PriorityThreadPoolExecutor.add_args(parser)
config = bt.Config(parser)
return config


TEST_ARGS = [
"bittensor",
"--config", "path/to/config.yaml",
"--strict",
"--no_version_checking"
]


def test_bittensor_cli_parser_enabled(monkeypatch):
"""Tests that the bt cli args are processed."""

monkeypatch.setattr(sys, "argv", TEST_ARGS)

with pytest.raises(InvalidConfigFile) as error:
_config_call()

assert "No such file or directory" in str(error)


def test_bittensor_cli_parser_disabled(monkeypatch):
"""Tests that the bt cli args are not processed."""
monkeypatch.setenv("BT_NO_PARSE_CLI_ARGS", "true")
monkeypatch.setattr(sys, "argv", TEST_ARGS)

config = _config_call()

assert config.config is False
assert config.strict is False
assert config.no_version_checking is False