Skip to content

Commit 313521d

Browse files
ibraheem-opentensorroman-opentensorcamfairchildthewhalekingAssh-codes
authored
Release/8.5.2 (#2584)
* Updates tests for btwallet 3.0.0 * fix get_delegates result decoding * Feat/use tx pool for set weights (#2534) * use the tx pool for setting/committing weights * add supports rpc method with cache * handle when state call is not possible (unlikely) * increment next index by one for correct nonce * use for set sync set weights also * oops, define in subtensor for sync methods * make tests less specific * try e2e test for commit weights * modify comments on test * add root set test helper * try upping submit timeout * add set weights e2e test * use high timeout on tests * add awaits and log netuid * chore: ruff * use sudo_set_admin_utils instead * don't increment next index for nonce * dont await sudo_set_admin_utils * lower test ext timeout to 12 * enable reg during test * use set hyp values instead * sleep after setting reg allowed * fix test_set_weights_uses_next_nonce * Use asyncstdlib for lru_cache of `AsyncSubstrateInterface.supports_rpc_method` * Increases sleep for txs in test_set_weights_uses_next_nonce --------- Co-authored-by: Benjamin Himes <37844818+thewhaleking@users.noreply.github.com> Co-authored-by: ibraheem-opentensor <ibraheem@opentensor.dev> Co-authored-by: Benjamin Himes <benhimes@opentensor.dev> * fix tests * add connection limit error handler * add test * Backmerge master to staging post 851 (#2557) Bumps version and changelog * improve handler * add async commit reveal impl * add new logic to async_subtensor * add unit tests * ruff * add uid check before processing * fix test * Use apt-get instead of apt for scripts (#2571) apt --> apt-get * fix _do_stake incorrect arguments error in staking.py add_stake sdk (after pybytes error is fixed in delegate_info.py) another error occurs, because _do_stake is incorrectly called on line 124 in staking.py returning an invalid arguments error, must add self (subtensor) param to fix this error. * Updates subtensor branch for e2e * tests fix * Bumps cr3 ffi * Bumps version and changelog * Updates changelog --------- Co-authored-by: Roman <167799377+roman-opentensor@users.noreply.github.com> Co-authored-by: Cameron Fairchild <cameron@opentensor.dev> Co-authored-by: Benjamin Himes <37844818+thewhaleking@users.noreply.github.com> Co-authored-by: Benjamin Himes <benhimes@opentensor.dev> Co-authored-by: Roman <roman@opentensor.dev> Co-authored-by: Assh-codes <121989988+Assh-codes@users.noreply.github.com>
1 parent cd2ccc2 commit 313521d

27 files changed

+1121
-65
lines changed

.github/workflows/e2e-subtensor-tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090

9191
- name: Setup subtensor repo
9292
working-directory: ${{ github.workspace }}/subtensor
93-
run: git checkout testnet
93+
run: git checkout main
9494

9595
- name: Run tests
9696
run: |

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Changelog
22

3+
## 8.5.2 /2025-01-17
4+
5+
## What's Changed
6+
* Feat/use tx pool for set weights by @camfairchild in https://github.com/opentensor/bittensor/pull/2534
7+
* fix get_delegates result decoding by @roman-opentensor in https://github.com/opentensor/bittensor/pull/2551
8+
* [SDK] Handle server connection limit by @roman-opentensor in https://github.com/opentensor/bittensor/pull/2553
9+
* Backmerge master to staging post 851 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2557
10+
* [SDK] Improve InvalidStatus handler by @roman-opentensor in https://github.com/opentensor/bittensor/pull/2558
11+
* [SDK] Add async version of commit reveal v3 by @roman-opentensor in https://github.com/opentensor/bittensor/pull/2560
12+
* Use apt-get instead of apt for scripts by @camfairchild in https://github.com/opentensor/bittensor/pull/2571
13+
* fix _do_stake incorrect arguments error in staking.py by @Assh-codes in https://github.com/opentensor/bittensor/pull/2574
14+
* Updates tests for btwallet 3.0.0 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2540
15+
* Bumps cr3 FFI by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2583
16+
17+
## New Contributors
18+
* @Assh-codes made their first contribution in https://github.com/opentensor/bittensor/pull/2574
19+
20+
**Full Changelog**: https://github.com/opentensor/bittensor/compare/v8.5.1...v8.5.2
21+
322
## 8.5.1 /2024-12-16
423

524
## What's Changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ LABEL bittensor.image.authors="bittensor.com" \
1212
ARG DEBIAN_FRONTEND=noninteractive
1313

1414
# Update the base image
15-
RUN apt update && apt upgrade -y
15+
RUN apt-get update && apt-get upgrade -y
1616
# Install bittensor
1717
## Install dependencies
18-
RUN apt install -y curl sudo nano git htop netcat-openbsd wget unzip tmux apt-utils cmake build-essential
18+
RUN apt-get install -y curl sudo nano git htop netcat-openbsd wget unzip tmux apt-utils cmake build-essential
1919
## Upgrade pip
2020
RUN pip3 install --upgrade pip
2121

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.5.1
1+
8.5.2

bittensor/core/async_subtensor.py

+35-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
SubnetHyperparameters,
2323
decode_account_id,
2424
)
25+
from bittensor.core.extrinsics.async_commit_reveal import commit_reveal_v3_extrinsic
2526
from bittensor.core.extrinsics.async_registration import register_extrinsic
2627
from bittensor.core.extrinsics.async_root import (
2728
set_root_weights_extrinsic,
@@ -1596,18 +1597,44 @@ async def set_weights(
15961597
15971598
This function is crucial in shaping the network's collective intelligence, where each neuron's learning and contribution are influenced by the weights it sets towards others【81†source】.
15981599
"""
1600+
retries = 0
1601+
success = False
1602+
if (
1603+
uid := await self.get_uid_for_hotkey_on_subnet(
1604+
wallet.hotkey.ss58_address, netuid
1605+
)
1606+
) is None:
1607+
return (
1608+
False,
1609+
f"Hotkey {wallet.hotkey.ss58_address} not registered in subnet {netuid}",
1610+
)
1611+
15991612
if (await self.commit_reveal_enabled(netuid=netuid)) is True:
16001613
# go with `commit reveal v3` extrinsic
1601-
raise NotImplementedError(
1602-
"Not implemented yet for AsyncSubtensor. Coming soon."
1603-
)
1614+
message = "No attempt made. Perhaps it is too soon to commit weights!"
1615+
while (
1616+
await self.blocks_since_last_update(netuid, uid)
1617+
> await self.weights_rate_limit(netuid)
1618+
and retries < max_retries
1619+
and success is False
1620+
):
1621+
logging.info(
1622+
f"Committing weights for subnet #{netuid}. Attempt {retries + 1} of {max_retries}."
1623+
)
1624+
success, message = await commit_reveal_v3_extrinsic(
1625+
subtensor=self,
1626+
wallet=wallet,
1627+
netuid=netuid,
1628+
uids=uids,
1629+
weights=weights,
1630+
version_key=version_key,
1631+
wait_for_inclusion=wait_for_inclusion,
1632+
wait_for_finalization=wait_for_finalization,
1633+
)
1634+
retries += 1
1635+
return success, message
16041636
else:
16051637
# go with classic `set weights extrinsic`
1606-
uid = await self.get_uid_for_hotkey_on_subnet(
1607-
wallet.hotkey.ss58_address, netuid
1608-
)
1609-
retries = 0
1610-
success = False
16111638
message = "No attempt made. Perhaps it is too soon to set weights!"
16121639
while (
16131640
retries < max_retries
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
from typing import Optional, Union, TYPE_CHECKING
2+
3+
import numpy as np
4+
from bittensor_commit_reveal import get_encrypted_commit
5+
from numpy.typing import NDArray
6+
7+
from bittensor.core.settings import version_as_int
8+
from bittensor.utils import format_error_message
9+
from bittensor.utils.btlogging import logging
10+
from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit
11+
12+
if TYPE_CHECKING:
13+
from bittensor_wallet import Wallet
14+
from bittensor.core.async_subtensor import AsyncSubtensor
15+
from bittensor.utils.registration import torch
16+
17+
18+
async def _do_commit_reveal_v3(
19+
subtensor: "AsyncSubtensor",
20+
wallet: "Wallet",
21+
netuid: int,
22+
commit: bytes,
23+
reveal_round: int,
24+
wait_for_inclusion: bool = False,
25+
wait_for_finalization: bool = False,
26+
) -> tuple[bool, Optional[str]]:
27+
"""
28+
Executes the commit-reveal phase 3 for a given netuid and commit, and optionally waits for extrinsic inclusion or finalization.
29+
30+
Arguments:
31+
subtensor: An instance of the Subtensor class.
32+
wallet: Wallet An instance of the Wallet class containing the user's keypair.
33+
netuid: int The network unique identifier.
34+
commit bytes The commit data in bytes format.
35+
reveal_round: int The round number for the reveal phase.
36+
wait_for_inclusion: bool, optional Flag indicating whether to wait for the extrinsic to be included in a block.
37+
wait_for_finalization: bool, optional Flag indicating whether to wait for the extrinsic to be finalized.
38+
39+
Returns:
40+
A tuple where the first element is a boolean indicating success or failure, and the second element is an optional string containing error message if any.
41+
"""
42+
logging.info(
43+
f"Committing weights hash [blue]{commit.hex()}[/blue] for subnet #[blue]{netuid}[/blue] with "
44+
f"reveal round [blue]{reveal_round}[/blue]..."
45+
)
46+
47+
call = await subtensor.substrate.compose_call(
48+
call_module="SubtensorModule",
49+
call_function="commit_crv3_weights",
50+
call_params={
51+
"netuid": netuid,
52+
"commit": commit,
53+
"reveal_round": reveal_round,
54+
},
55+
)
56+
extrinsic = await subtensor.substrate.create_signed_extrinsic(
57+
call=call,
58+
keypair=wallet.hotkey,
59+
)
60+
61+
response = await subtensor.substrate.submit_extrinsic(
62+
subtensor=subtensor,
63+
extrinsic=extrinsic,
64+
wait_for_inclusion=wait_for_inclusion,
65+
wait_for_finalization=wait_for_finalization,
66+
)
67+
68+
if not wait_for_finalization and not wait_for_inclusion:
69+
return True, "Not waiting for finalization or inclusion."
70+
71+
if await response.is_success:
72+
return True, None
73+
74+
return False, format_error_message(await response.error_message)
75+
76+
77+
async def commit_reveal_v3_extrinsic(
78+
subtensor: "AsyncSubtensor",
79+
wallet: "Wallet",
80+
netuid: int,
81+
uids: Union[NDArray[np.int64], "torch.LongTensor", list],
82+
weights: Union[NDArray[np.float32], "torch.FloatTensor", list],
83+
version_key: int = version_as_int,
84+
wait_for_inclusion: bool = False,
85+
wait_for_finalization: bool = False,
86+
) -> tuple[bool, str]:
87+
"""
88+
Commits and reveals weights for given subtensor and wallet with provided uids and weights.
89+
90+
Arguments:
91+
subtensor: The Subtensor instance.
92+
wallet: The wallet to use for committing and revealing.
93+
netuid: The id of the network.
94+
uids: The uids to commit.
95+
weights: The weights associated with the uids.
96+
version_key: The version key to use for committing and revealing. Default is version_as_int.
97+
wait_for_inclusion: Whether to wait for the inclusion of the transaction. Default is False.
98+
wait_for_finalization: Whether to wait for the finalization of the transaction. Default is False.
99+
100+
Returns:
101+
tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure, and the second element is a message associated with the result.
102+
"""
103+
try:
104+
# Convert uids and weights
105+
if isinstance(uids, list):
106+
uids = np.array(uids, dtype=np.int64)
107+
if isinstance(weights, list):
108+
weights = np.array(weights, dtype=np.float32)
109+
110+
# Reformat and normalize.
111+
uids, weights = convert_weights_and_uids_for_emit(uids, weights)
112+
113+
current_block = await subtensor.substrate.get_block_number(None)
114+
subnet_hyperparameters = await subtensor.get_subnet_hyperparameters(netuid)
115+
tempo = subnet_hyperparameters.tempo
116+
subnet_reveal_period_epochs = (
117+
subnet_hyperparameters.commit_reveal_weights_interval
118+
)
119+
120+
# Encrypt `commit_hash` with t-lock and `get reveal_round`
121+
commit_for_reveal, reveal_round = get_encrypted_commit(
122+
uids=uids,
123+
weights=weights,
124+
version_key=version_key,
125+
tempo=tempo,
126+
current_block=current_block,
127+
netuid=netuid,
128+
subnet_reveal_period_epochs=subnet_reveal_period_epochs,
129+
)
130+
131+
success, message = await _do_commit_reveal_v3(
132+
subtensor=subtensor,
133+
wallet=wallet,
134+
netuid=netuid,
135+
commit=commit_for_reveal,
136+
reveal_round=reveal_round,
137+
wait_for_inclusion=wait_for_inclusion,
138+
wait_for_finalization=wait_for_finalization,
139+
)
140+
141+
if success is not True:
142+
logging.error(message)
143+
return False, message
144+
145+
logging.success(
146+
f"[green]Finalized![/green] Weights commited with reveal round [blue]{reveal_round}[/blue]."
147+
)
148+
return True, f"reveal_round:{reveal_round}"
149+
150+
except Exception as e:
151+
logging.error(f":cross_mark: [red]Failed. Error:[/red] {e}")
152+
return False, str(e)

bittensor/core/extrinsics/async_weights.py

+12
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ async def _do_set_weights(
5858
"version_key": version_key,
5959
},
6060
)
61+
62+
next_nonce = await subtensor.substrate.get_account_next_index(
63+
wallet.hotkey.ss58_address
64+
)
65+
6166
# Period dictates how long the extrinsic will stay as part of waiting pool
6267
extrinsic = await subtensor.substrate.create_signed_extrinsic(
6368
call=call,
6469
keypair=wallet.hotkey,
6570
era={"period": 5},
71+
nonce=next_nonce,
6672
)
6773
response = await subtensor.substrate.submit_extrinsic(
6874
extrinsic,
@@ -180,9 +186,15 @@ async def _do_commit_weights(
180186
"commit_hash": commit_hash,
181187
},
182188
)
189+
190+
next_nonce = await subtensor.substrate.get_account_next_index(
191+
wallet.hotkey.ss58_address
192+
)
193+
183194
extrinsic = await subtensor.substrate.create_signed_extrinsic(
184195
call=call,
185196
keypair=wallet.hotkey,
197+
nonce=next_nonce,
186198
)
187199
response = await subtensor.substrate.submit_extrinsic(
188200
substrate=subtensor.substrate,

bittensor/core/extrinsics/commit_weights.py

+2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ def do_commit_weights(
6666
"commit_hash": commit_hash,
6767
},
6868
)
69+
next_nonce = self.get_account_next_index(wallet.hotkey.ss58_address)
6970
extrinsic = self.substrate.create_signed_extrinsic(
7071
call=call,
7172
keypair=wallet.hotkey,
73+
nonce=next_nonce,
7274
)
7375
response = submit_extrinsic(
7476
subtensor=self,

bittensor/core/extrinsics/set_weights.py

+2
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ def do_set_weights(
7676
"version_key": version_key,
7777
},
7878
)
79+
next_nonce = self.get_account_next_index(wallet.hotkey.ss58_address)
7980
# Period dictates how long the extrinsic will stay as part of waiting pool
8081
extrinsic = self.substrate.create_signed_extrinsic(
8182
call=call,
8283
keypair=wallet.hotkey,
8384
era={"period": period},
85+
nonce=next_nonce,
8486
)
8587
response = submit_extrinsic(
8688
self,

bittensor/core/extrinsics/staking.py

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def __do_add_stake_single(
122122
raise NotDelegateError("Hotkey: {} is not a delegate.".format(hotkey_ss58))
123123

124124
success = _do_stake(
125+
self=subtensor,
125126
wallet=wallet,
126127
hotkey_ss58=hotkey_ss58,
127128
amount=amount,

bittensor/core/settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1616
# DEALINGS IN THE SOFTWARE.
1717

18-
__version__ = "8.5.1"
18+
__version__ = "8.5.2"
1919

2020
import os
2121
import re

0 commit comments

Comments
 (0)