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/9.0.3 #2712

Merged
merged 73 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
52e68e3
Rename `install_templates`, have it correctly use the bittensor filep…
thewhaleking Feb 18, 2025
045c1e4
Increase the waiting period to reduce flakiness in `test_commit_weigh…
thewhaleking Feb 18, 2025
1e0e358
Merge branch 'staging' into fix/thewhaleking/fix-e2e-test-installation
thewhaleking Feb 18, 2025
7aef0c5
Remove bittensor installation/uninstallation, appears not to actually…
thewhaleking Feb 18, 2025
e1ef6c1
Updates test incentive
ibraheem-opentensor Feb 20, 2025
ef53e53
Merge branch 'tests/rust_upgrade' into fix/e2e-test-incentive
zyzniewski-reef Feb 21, 2025
b8ee726
tests: increase waiting time in test_incentive
zyzniewski-reef Feb 21, 2025
070fa43
Merge branch 'staging' into fix/e2e-test-incentive
zyzniewski-reef Feb 21, 2025
6186366
Merge branch 'staging' into fix/e2e-test-incentive
roman-opentensor Feb 21, 2025
8347495
Merge branch 'staging' into fix/e2e-test-incentive
ibraheem-opentensor Feb 22, 2025
7703786
fix: typos in config test
EricHasegawa Feb 24, 2025
f602222
Merge branch 'staging' into master
thewhaleking Feb 24, 2025
5e498c8
Merge branch 'staging' into master
thewhaleking Feb 24, 2025
ce57322
Merge branch 'staging' into master
thewhaleking Feb 24, 2025
f355b9c
Merge branch 'staging' into master
thewhaleking Feb 25, 2025
8245f64
Merge branch 'staging' into fix/e2e-test-incentive
zyzniewski-reef Feb 25, 2025
0adc99a
tests: fix e2e wait_epoch
zyzniewski-reef Feb 25, 2025
8b60b64
tests: improve test_incentive waiting time
zyzniewski-reef Feb 25, 2025
fa1e8fe
Fixes get_all_commitments, adds tests.
thewhaleking Feb 25, 2025
c172d44
Merge branch 'staging' into fix/thewhaleking/get-all-commitments-fix
thewhaleking Feb 25, 2025
0f8d278
Merge pull request #2693 from EricHasegawa/master
thewhaleking Feb 25, 2025
313467d
Merge branch 'staging' into fix/thewhaleking/get-all-commitments-fix
thewhaleking Feb 25, 2025
46a08fe
Use `.value` in e2e test
thewhaleking Feb 25, 2025
a25bb64
tests: wait 4 epochs for e2e test_incentive
zyzniewski-reef Feb 25, 2025
28a77a5
Removes limits in async + unstake_mul
ibraheem-opentensor Feb 25, 2025
6f7c039
ruff
ibraheem-opentensor Feb 25, 2025
4ec4618
Merge pull request #2701 from opentensor/fix/remove-limits-unstaking
ibraheem-opentensor Feb 25, 2025
6eac932
Merge branch 'staging' into fix/thewhaleking/get-all-commitments-fix
ibraheem-opentensor Feb 25, 2025
80634e0
Merge pull request #2699 from opentensor/fix/thewhaleking/get-all-com…
thewhaleking Feb 25, 2025
dfaf1a2
Merge branch 'staging' into fix/thewhaleking/e2e-uses-dot-value
thewhaleking Feb 25, 2025
d32cd83
Merge branch 'staging' into fix/e2e-test-incentive
ibraheem-opentensor Feb 25, 2025
96faab4
Merge pull request #2700 from opentensor/fix/thewhaleking/e2e-uses-do…
thewhaleking Feb 25, 2025
eb11a68
Merge branch 'staging' into fix/thewhaleking/fix-e2e-test-installation
thewhaleking Feb 25, 2025
594a70f
Merge branch 'staging' into fix/e2e-test-incentive
thewhaleking Feb 25, 2025
78e2ff6
Adds a try:except catch for the `__del__` method, as `self.close_sess…
thewhaleking Feb 25, 2025
344fdb1
Add tests
thewhaleking Feb 25, 2025
cfdb40c
Added debug logging.
thewhaleking Feb 25, 2025
ef31635
Merge pull request #2681 from opentensor/fix/thewhaleking/fix-e2e-tes…
thewhaleking Feb 25, 2025
8377fb7
Merge branch 'staging' into fix/thewhaleking/dendrite-del-method
thewhaleking Feb 25, 2025
d682c50
Merge branch 'staging' into fix/e2e-test-incentive
thewhaleking Feb 25, 2025
ab1676d
tests: wait_epoch (instead of fixed time) in test_set_weights
zyzniewski-reef Feb 26, 2025
ecabcde
tests: wait 4 epochs in test_set_weights
zyzniewski-reef Feb 26, 2025
380c5a3
Merge pull request #2702 from opentensor/fix/thewhaleking/dendrite-de…
thewhaleking Feb 26, 2025
cea1b70
Merge branch 'staging' into tests/zyzniewski/fix_e2e_test_set_weights
thewhaleking Feb 26, 2025
ede515a
Merge branch 'staging' into fix/e2e-test-incentive
thewhaleking Feb 26, 2025
b9561dd
Adds `get_timestamp` method to `Subtensor` and `AsyncSubtensor`
thewhaleking Feb 26, 2025
a641141
Merge branch 'staging' into feat/thewhaleking/add-timestamp
thewhaleking Feb 26, 2025
b30aea0
Python 3.9 compatibility
thewhaleking Feb 26, 2025
ad0cc3d
Mypy…
thewhaleking Feb 26, 2025
5804210
Merge pull request #2703 from opentensor/tests/zyzniewski/fix_e2e_tes…
zyzniewski-reef Feb 26, 2025
d352fd5
Merge branch 'staging' into fix/e2e-test-incentive
zyzniewski-reef Feb 26, 2025
7b7c1cf
fix: async get_delegated
zyzniewski-reef Feb 26, 2025
427b55a
Merge branch 'staging' into feat/thewhaleking/add-timestamp
thewhaleking Feb 26, 2025
a888521
Merge pull request #2688 from opentensor/fix/e2e-test-incentive
zyzniewski-reef Feb 26, 2025
4911c77
fix: properly mock data_chain class methods
zyzniewski-reef Feb 26, 2025
b34a61b
Merge branch 'staging' into tests/zyzniewski/proper_mock
zyzniewski-reef Feb 26, 2025
e696b5e
ruff formating
zyzniewski-reef Feb 26, 2025
68bd49c
Merge branch 'staging' into feat/thewhaleking/add-timestamp
thewhaleking Feb 26, 2025
19de20b
Merge branch 'staging' into fix/zyzniewski/async_get_delegated
ibraheem-opentensor Feb 26, 2025
a88e2d7
Merge pull request #2704 from opentensor/feat/thewhaleking/add-timestamp
thewhaleking Feb 26, 2025
61c8c70
Merge branch 'staging' into fix/zyzniewski/async_get_delegated
ibraheem-opentensor Feb 26, 2025
02ea729
Merge pull request #2706 from opentensor/fix/zyzniewski/async_get_del…
ibraheem-opentensor Feb 26, 2025
3e8ffff
Merge branch 'staging' into tests/zyzniewski/proper_mock
thewhaleking Feb 26, 2025
bc3d43b
Merge pull request #2705 from opentensor/tests/zyzniewski/proper_mock
zyzniewski-reef Feb 26, 2025
5cd192e
Installs btcli along with bittensor for the `install.sh` script.
thewhaleking Feb 26, 2025
8be7bc8
Removed legacy text.
thewhaleking Feb 26, 2025
3106ee7
Merge pull request #2708 from opentensor/feat/thewhaleking/install-bt…
thewhaleking Feb 26, 2025
c6a63ea
Bumps deps
ibraheem-opentensor Feb 26, 2025
1bfe0b8
Merge pull request #2710 from opentensor/bump/async-substrate-wallet-…
ibraheem-opentensor Feb 26, 2025
bf76364
Merge branch 'master' into backmerge/main-staging-902
ibraheem-opentensor Feb 26, 2025
48dd95e
Merge branch 'staging' into backmerge/main-staging-902
ibraheem-opentensor Feb 26, 2025
ed700b2
Merge pull request #2711 from opentensor/backmerge/main-staging-902
ibraheem-opentensor Feb 27, 2025
4f57bd1
Bumps version and changelog
ibraheem-opentensor Feb 27, 2025
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: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Changelog

## 9.0.3 /2025-02-26

## What's Changed
* Release/9.0.2 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2696
* fix: typos in config test by @EricHasegawa in https://github.com/opentensor/bittensor/pull/2693
* Removes limits in async + unstake_multiple by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2701
* Fixes get_all_commitments, adds tests. by @thewhaleking in https://github.com/opentensor/bittensor/pull/2699
* Use `.value` in e2e test by @thewhaleking in https://github.com/opentensor/bittensor/pull/2700
* Fix e2e test setup by @thewhaleking in https://github.com/opentensor/bittensor/pull/2681
* Dendrite `__del__` method fix by @thewhaleking in https://github.com/opentensor/bittensor/pull/2702
* Fix E2E test_set_weights by @zyzniewski-reef in https://github.com/opentensor/bittensor/pull/2703
* Updates test incentive by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2688
* Add `get_timestamp` method by @thewhaleking in https://github.com/opentensor/bittensor/pull/2704
* fix: async get_delegated by @zyzniewski-reef in https://github.com/opentensor/bittensor/pull/2706
* Properly mock data_chain class methods by @zyzniewski-reef in https://github.com/opentensor/bittensor/pull/2705
* Install btcli from install sh by @thewhaleking in https://github.com/opentensor/bittensor/pull/2708
* Bumps dependencies of async substrate + btwallet by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2710
* Backmerge/main to staging 902 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2711

## New Contributors
* @EricHasegawa made their first contribution in https://github.com/opentensor/bittensor/pull/2693

**Full Changelog**: https://github.com/opentensor/bittensor/compare/v9.0.2...v9.0.3

## 9.0.2 /2025-02-24

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.0.2
9.0.3
36 changes: 34 additions & 2 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import copy
from datetime import datetime, timezone
import ssl
from functools import partial
from typing import Optional, Any, Union, Iterable, TYPE_CHECKING
Expand Down Expand Up @@ -27,6 +28,7 @@
decode_account_id,
DynamicInfo,
)
from bittensor.core.chain_data.delegate_info import DelegatedInfo
from bittensor.core.chain_data.utils import decode_metadata
from bittensor.core.config import Config
from bittensor.core.errors import SubstrateRequestException
Expand Down Expand Up @@ -999,7 +1001,7 @@ async def get_all_commitments(
)
result = {}
async for id_, value in query:
result[decode_account_id(id_[0])] = decode_account_id(value)
result[decode_account_id(id_[0])] = decode_metadata(value)
return result

async def get_current_weight_commit_info(
Expand Down Expand Up @@ -1219,7 +1221,7 @@ async def get_delegated(
if not result:
return []

return DelegateInfo.delegated_list_from_dicts(result)
return DelegatedInfo.list_from_dicts(result)

async def get_delegates(
self,
Expand Down Expand Up @@ -2744,6 +2746,36 @@ async def weights_rate_limit(
)
return None if call is None else int(call)

async def get_timestamp(
self,
block: Optional[int] = None,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> datetime:
"""
Retrieves the datetime timestamp for a given block

Arguments:
block: The blockchain block number for the query. Do not specify if specifying block_hash or reuse_block.
block_hash: The blockchain block_hash representation of the block id. Do not specify if specifying block
or reuse_block.
reuse_block: Whether to reuse the last-used blockchain block hash. Do not specify if specifying block or
block_hash.

Returns:
datetime object for the timestamp of the block
"""
unix = (
await self.query_module(
"Timestamp",
"Now",
block=block,
block_hash=block_hash,
reuse_block=reuse_block,
)
).value
return datetime.fromtimestamp(unix / 1000, tz=timezone.utc)

# Extrinsics helper ================================================================================================

async def sign_and_send_extrinsic(
Expand Down
9 changes: 8 additions & 1 deletion bittensor/core/dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,14 @@ def __del__(self):
# ... some operations ...
del dendrite # This will implicitly invoke the __del__ method and close the session.
"""
self.close_session()
try:
self.close_session()
except RuntimeError:
if self._session:
logging.debug(
"A Dendrite session was unable to be closed during garbage-collection of the Dendrite object. This "
"usually indicates that you were not using the async context manager."
)


# For back-compatibility with torch
Expand Down
14 changes: 0 additions & 14 deletions bittensor/core/extrinsics/asyncex/staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,6 @@ async def add_stake_multiple_extrinsic(
if staking_response is True: # If we successfully staked.
# We only wait here if we expect finalization.

if idx < len(hotkey_ss58s) - 1:
# Wait for tx rate limit.
tx_query = await subtensor.substrate.query(
module="SubtensorModule", storage_function="TxRateLimit"
)
tx_rate_limit_blocks: int = getattr(tx_query, "value", 0)
if tx_rate_limit_blocks > 0:
logging.error(
f":hourglass: [yellow]Waiting for tx rate limit: [white]{tx_rate_limit_blocks}[/white] "
f"blocks[/yellow]"
)
# 12 seconds per block
await asyncio.sleep(tx_rate_limit_blocks * 12)

if not wait_for_finalization and not wait_for_inclusion:
old_balance -= staking_balance
successful_stakes += 1
Expand Down
12 changes: 0 additions & 12 deletions bittensor/core/extrinsics/asyncex/unstaking.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,6 @@ async def unstake_multiple_extrinsic(
if staking_response is True: # If we successfully unstaked.
# We only wait here if we expect finalization.

if idx < len(hotkey_ss58s) - 1:
# Wait for tx rate limit.
tx_rate_limit_blocks = await subtensor.tx_rate_limit()
if tx_rate_limit_blocks > 0:
logging.info(
f":hourglass: [yellow]Waiting for tx rate limit: "
f"[white]{tx_rate_limit_blocks}[/white] blocks[/yellow]"
)
await asyncio.sleep(
tx_rate_limit_blocks * 12
) # 12 seconds per block

if not wait_for_finalization and not wait_for_inclusion:
successful_unstakes += 1
continue
Expand Down
11 changes: 0 additions & 11 deletions bittensor/core/extrinsics/unstaking.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import time
from typing import Optional, TYPE_CHECKING

from bittensor.core.errors import StakeError, NotRegisteredError
Expand Down Expand Up @@ -266,16 +265,6 @@ def unstake_multiple_extrinsic(
if staking_response is True: # If we successfully unstaked.
# We only wait here if we expect finalization.

if idx < len(hotkey_ss58s) - 1:
# Wait for tx rate limit.
tx_rate_limit_blocks = subtensor.tx_rate_limit()
if tx_rate_limit_blocks > 0:
logging.info(
f":hourglass: [yellow]Waiting for tx rate limit: "
f"[white]{tx_rate_limit_blocks}[/white] blocks[/yellow]"
)
time.sleep(tx_rate_limit_blocks * 12) # 12 seconds per block

if not wait_for_finalization and not wait_for_inclusion:
successful_unstakes += 1
continue
Expand Down
2 changes: 1 addition & 1 deletion bittensor/core/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "9.0.2"
__version__ = "9.0.3"

import os
import re
Expand Down
17 changes: 16 additions & 1 deletion bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import copy
from datetime import datetime, timezone

from functools import lru_cache
from typing import TYPE_CHECKING, Any, Iterable, Optional, Union, cast

Expand Down Expand Up @@ -754,7 +756,7 @@ def get_all_commitments(
)
result = {}
for id_, value in query:
result[decode_account_id(id_[0])] = decode_account_id(value)
result[decode_account_id(id_[0])] = decode_metadata(value)
return result

def get_current_weight_commit_info(
Expand Down Expand Up @@ -2070,6 +2072,19 @@ def weights_rate_limit(
)
return None if call is None else int(call)

def get_timestamp(self, block: Optional[int] = None) -> datetime:
"""
Retrieves the datetime timestamp for a given block

Arguments:
block: The blockchain block number for the query.

Returns:
datetime object for the timestamp of the block
"""
unix = cast(ScaleObj, self.query_module("Timestamp", "Now", block=block)).value
return datetime.fromtimestamp(unix / 1000, tz=timezone.utc)

# Extrinsics helper ================================================================================================

def sign_and_send_extrinsic(
Expand Down
4 changes: 3 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ linux_install_bittensor() {
git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || (cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard ; git clean -xdf)
ohai "Installing bittensor"
$python -m pip install -e ~/.bittensor/bittensor/
$python -m pip install -U bittensor-cli
exit_on_error $?
}

Expand Down Expand Up @@ -163,10 +164,11 @@ mac_update_pip() {
}

mac_install_bittensor() {
ohai "Cloning bittensor@text_prompting into ~/.bittensor/bittensor"
ohai "Cloning bittensor into ~/.bittensor/bittensor"
git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || (cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard; git clean -xdf)
ohai "Installing bittensor"
$python -m pip install -e ~/.bittensor/bittensor/
$python -m pip install -U bittensor-cli
exit_on_error $?
deactivate
}
Expand Down
8 changes: 7 additions & 1 deletion tests/e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import pytest
from async_substrate_interface import SubstrateInterface
from bittensor.core.subtensor import Subtensor

from bittensor.core.async_subtensor import AsyncSubtensor
from bittensor.core.subtensor import Subtensor
from bittensor.utils.btlogging import logging
from tests.e2e_tests.utils.e2e_test_utils import (
Templates,
Expand Down Expand Up @@ -101,6 +102,11 @@ def subtensor(local_chain):
return Subtensor(network="ws://localhost:9944")


@pytest.fixture
def async_subtensor(local_chain):
return AsyncSubtensor(network="ws://localhost:9944")


@pytest.fixture
def alice_wallet():
keypair, wallet = setup_wallet("//Alice")
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e_tests/test_commit_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ async def test_commit_weights_uses_next_nonce(local_chain, subtensor, alice_wall
assert success is True

# Wait a few blocks
await asyncio.sleep(2) # Wait for the txs to be included in the chain
await asyncio.sleep(10) # Wait for the txs to be included in the chain

# Query the WeightCommits storage map for all three salts
weight_commits = subtensor.query_module(
Expand Down
58 changes: 58 additions & 0 deletions tests/e2e_tests/test_commitment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,61 @@ def test_commitment(subtensor, alice_wallet):
netuid=1,
uid=uid,
)

assert (
subtensor.get_all_commitments(netuid=1)[alice_wallet.hotkey.ss58_address]
== "Hello World!"
)


@pytest.mark.asyncio
async def test_commitment_async(async_subtensor, alice_wallet):
async with async_subtensor as sub:
with pytest.raises(SubstrateRequestException, match="AccountNotAllowedCommit"):
await sub.set_commitment(
alice_wallet,
netuid=1,
data="Hello World!",
)

assert await sub.burned_register(
alice_wallet,
netuid=1,
)

uid = await sub.get_uid_for_hotkey_on_subnet(
alice_wallet.hotkey.ss58_address,
netuid=1,
)

assert uid is not None

assert "" == await sub.get_commitment(
netuid=1,
uid=uid,
)

assert await sub.set_commitment(
alice_wallet,
netuid=1,
data="Hello World!",
)

with pytest.raises(
SubstrateRequestException,
match="CommitmentSetRateLimitExceeded",
):
await sub.set_commitment(
alice_wallet,
netuid=1,
data="Hello World!",
)

assert "Hello World!" == await sub.get_commitment(
netuid=1,
uid=uid,
)

assert (await sub.get_all_commitments(netuid=1))[
alice_wallet.hotkey.ss58_address
] == "Hello World!"
18 changes: 18 additions & 0 deletions tests/e2e_tests/test_cross_subtensor_compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from datetime import datetime
import pytest


@pytest.mark.asyncio
async def test_get_timestamp(subtensor, async_subtensor, local_chain):
with subtensor:
block_number = subtensor.get_current_block()
assert isinstance(
subtensor.get_timestamp(), datetime
) # verify it works with no block number specified
sync_result = subtensor.get_timestamp(
block=block_number
) # verify it works with block number specified
async with async_subtensor:
assert isinstance(await async_subtensor.get_timestamp(), datetime)
async_result = await async_subtensor.get_timestamp(block=block_number)
assert sync_result == async_result
Loading
Loading