Skip to content

Commit 090a165

Browse files
authored
Merge branch 'staging' into fix/zyzniewski/unittests_warnings
2 parents 8929358 + 0f4db69 commit 090a165

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2168
-1463
lines changed

.github/workflows/docker_release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
steps:
2020
- name: Check out code
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
2222

2323
- name: Install cosign
2424
uses: sigstore/cosign-installer@v3
@@ -48,4 +48,4 @@ jobs:
4848
DIGEST: ${{ steps.build.outputs.digest }}
4949
TAGS: ${{ steps.build.outputs.tags }}
5050
run: |
51-
echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
51+
echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212
branches: [master, development, staging]
1313
types: [ opened, synchronize, reopened, ready_for_review ]
1414

15+
schedule:
16+
- cron: '0 9 * * *' # Run every night at 2:00 PST
17+
1518
workflow_dispatch:
1619
inputs:
1720
verbose:

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: Build Python distribution
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717

1818
- name: Set up Python
1919
uses: actions/setup-python@v4
@@ -69,4 +69,4 @@ jobs:
6969
uses: pypa/gh-action-pypi-publish@release/v1
7070
with:
7171
verbose: true
72-
print-hash: true
72+
print-hash: true

bittensor/core/async_subtensor.py

Lines changed: 262 additions & 79 deletions
Large diffs are not rendered by default.

bittensor/core/extrinsics/asyncex/commit_reveal.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from typing import Optional, Union, TYPE_CHECKING
44

55
import numpy as np
6-
from bittensor_commit_reveal import get_encrypted_commit
6+
from bittensor_drand import get_encrypted_commit
77
from numpy.typing import NDArray
88

99
from bittensor.core.settings import version_as_int
1010
from bittensor.utils.btlogging import logging
11-
from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit
11+
from bittensor.utils.weight_utils import convert_and_normalize_weights_and_uids
1212

1313
if TYPE_CHECKING:
1414
from bittensor_wallet import Wallet
@@ -24,23 +24,26 @@ async def _do_commit_reveal_v3(
2424
reveal_round: int,
2525
wait_for_inclusion: bool = False,
2626
wait_for_finalization: bool = False,
27-
) -> tuple[bool, Optional[str]]:
27+
period: Optional[int] = None,
28+
) -> tuple[bool, str]:
2829
"""
29-
Executes the commit-reveal phase 3 for a given netuid and commit, and optionally waits for extrinsic inclusion or
30-
finalization.
30+
Executes commit-reveal phase 3 for a given netuid and commit, and optionally waits for extrinsic inclusion or finalization.
3131
3232
Arguments:
3333
subtensor: An instance of the AsyncSubtensor class.
3434
wallet: Wallet An instance of the Wallet class containing the user's keypair.
3535
netuid: int The network unique identifier.
36-
commit bytes The commit data in bytes format.
36+
commit: bytes The commit data in bytes format.
3737
reveal_round: int The round number for the reveal phase.
3838
wait_for_inclusion: bool, optional Flag indicating whether to wait for the extrinsic to be included in a block.
3939
wait_for_finalization: bool, optional Flag indicating whether to wait for the extrinsic to be finalized.
40+
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
41+
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
42+
You can think of it as an expiration date for the transaction.
4043
4144
Returns:
42-
A tuple where the first element is a boolean indicating success or failure, and the second element is an
43-
optional string containing error message if any.
45+
A tuple where the first element is a boolean indicating success or failure, and the second element is a
46+
string containing an error message if any.
4447
"""
4548
logging.info(
4649
f"Committing weights hash [blue]{commit.hex()}[/blue] for subnet #[blue]{netuid}[/blue] with "
@@ -57,7 +60,12 @@ async def _do_commit_reveal_v3(
5760
},
5861
)
5962
return await subtensor.sign_and_send_extrinsic(
60-
call, wallet, wait_for_inclusion, wait_for_finalization, sign_with="hotkey"
63+
call=call,
64+
wallet=wallet,
65+
wait_for_inclusion=wait_for_inclusion,
66+
wait_for_finalization=wait_for_finalization,
67+
sign_with="hotkey",
68+
period=period,
6169
)
6270

6371

@@ -70,10 +78,11 @@ async def commit_reveal_v3_extrinsic(
7078
version_key: int = version_as_int,
7179
wait_for_inclusion: bool = False,
7280
wait_for_finalization: bool = False,
73-
block_time: float = 12.0,
81+
block_time: Union[int, float] = 12.0,
82+
period: Optional[int] = None,
7483
) -> tuple[bool, str]:
7584
"""
76-
Commits and reveals weights for given subtensor and wallet with provided uids and weights.
85+
Commits and reveals weights for a given subtensor and wallet with provided uids and weights.
7786
7887
Arguments:
7988
subtensor: The AsyncSubtensor instance.
@@ -84,21 +93,17 @@ async def commit_reveal_v3_extrinsic(
8493
version_key: The version key to use for committing and revealing. Default is version_as_int.
8594
wait_for_inclusion: Whether to wait for the inclusion of the transaction. Default is False.
8695
wait_for_finalization: Whether to wait for the finalization of the transaction. Default is False.
87-
block_time (float): The amount of seconds for block duration. Default is 12.0 seconds.
96+
block_time (float): The number of seconds for block duration. Default is 12.0 seconds.
97+
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
98+
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
99+
You can think of it as an expiration date for the transaction.
88100
89101
Returns:
90102
tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure, and the second
91103
element is a message associated with the result
92104
"""
93105
try:
94-
# Convert uids and weights
95-
if isinstance(uids, list):
96-
uids = np.array(uids, dtype=np.int64)
97-
if isinstance(weights, list):
98-
weights = np.array(weights, dtype=np.float32)
99-
100-
# Reformat and normalize.
101-
uids, weights = convert_weights_and_uids_for_emit(uids, weights)
106+
uids, weights = convert_and_normalize_weights_and_uids(uids, weights)
102107

103108
current_block = await subtensor.substrate.get_block(None)
104109
subnet_hyperparameters = await subtensor.get_subnet_hyperparameters(
@@ -127,6 +132,7 @@ async def commit_reveal_v3_extrinsic(
127132
reveal_round=reveal_round,
128133
wait_for_inclusion=wait_for_inclusion,
129134
wait_for_finalization=wait_for_finalization,
135+
period=period,
130136
)
131137

132138
if success is not True:

bittensor/core/extrinsics/asyncex/move_stake.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
from typing import TYPE_CHECKING
2+
from typing import TYPE_CHECKING, Optional
33

44
from bittensor.utils.balance import Balance
55
from bittensor.utils.btlogging import logging
@@ -18,6 +18,7 @@ async def _get_stake_in_origin_and_dest(
1818
origin_netuid: int,
1919
destination_netuid: int,
2020
) -> tuple[Balance, Balance]:
21+
"""Gets the current stake balances for both origin and destination addresses in their respective subnets."""
2122
block_hash = await subtensor.substrate.get_chain_head()
2223
stake_in_origin, stake_in_destination = await asyncio.gather(
2324
subtensor.get_stake(
@@ -46,6 +47,7 @@ async def transfer_stake_extrinsic(
4647
amount: Balance,
4748
wait_for_inclusion: bool = True,
4849
wait_for_finalization: bool = False,
50+
period: Optional[int] = None,
4951
) -> bool:
5052
"""
5153
Transfers stake from one coldkey to another in the Bittensor network.
@@ -60,6 +62,9 @@ async def transfer_stake_extrinsic(
6062
amount (Balance): The amount of stake to transfer as a `Balance` object.
6163
wait_for_inclusion (bool): If True, waits for transaction inclusion in a block. Defaults to `True`.
6264
wait_for_finalization (bool): If True, waits for transaction finalization. Defaults to `False`.
65+
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
66+
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
67+
You can think of it as an expiration date for the transaction.
6368
6469
Returns:
6570
bool: True if the transfer was successful, False otherwise.
@@ -77,7 +82,7 @@ async def transfer_stake_extrinsic(
7782

7883
# Check sufficient stake
7984
stake_in_origin, stake_in_destination = await _get_stake_in_origin_and_dest(
80-
subtensor,
85+
subtensor=subtensor,
8186
origin_hotkey_ss58=hotkey_ss58,
8287
destination_hotkey_ss58=hotkey_ss58,
8388
origin_coldkey_ss58=wallet.coldkeypub.ss58_address,
@@ -116,6 +121,7 @@ async def transfer_stake_extrinsic(
116121
wallet=wallet,
117122
wait_for_inclusion=wait_for_inclusion,
118123
wait_for_finalization=wait_for_finalization,
124+
period=period,
119125
)
120126

121127
if success:
@@ -126,7 +132,7 @@ async def transfer_stake_extrinsic(
126132

127133
# Get updated stakes
128134
origin_stake, dest_stake = await _get_stake_in_origin_and_dest(
129-
subtensor,
135+
subtensor=subtensor,
130136
origin_hotkey_ss58=hotkey_ss58,
131137
destination_hotkey_ss58=hotkey_ss58,
132138
origin_coldkey_ss58=wallet.coldkeypub.ss58_address,
@@ -163,6 +169,7 @@ async def swap_stake_extrinsic(
163169
safe_staking: bool = False,
164170
allow_partial_stake: bool = False,
165171
rate_tolerance: float = 0.005,
172+
period: Optional[int] = None,
166173
) -> bool:
167174
"""
168175
Swaps stake from one subnet to another for a given hotkey in the Bittensor network.
@@ -178,7 +185,10 @@ async def swap_stake_extrinsic(
178185
wait_for_finalization (bool): If True, waits for transaction finalization. Defaults to False.
179186
safe_staking (bool): If true, enables price safety checks to protect against price impact.
180187
allow_partial_stake (bool): If true, allows partial stake swaps when the full amount would exceed the price tolerance.
181-
rate_tolerance (float): Maximum allowed increase in price ratio (0.005 = 0.5%).
188+
rate_tolerance (float): Maximum allowed increase in a price ratio (0.005 = 0.5%).
189+
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
190+
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
191+
You can think of it as an expiration date for the transaction.
182192
183193
Returns:
184194
bool: True if the swap was successful, False otherwise.
@@ -195,7 +205,7 @@ async def swap_stake_extrinsic(
195205

196206
# Check sufficient stake
197207
stake_in_origin, stake_in_destination = await _get_stake_in_origin_and_dest(
198-
subtensor,
208+
subtensor=subtensor,
199209
origin_hotkey_ss58=hotkey_ss58,
200210
destination_hotkey_ss58=hotkey_ss58,
201211
origin_coldkey_ss58=wallet.coldkeypub.ss58_address,
@@ -259,6 +269,7 @@ async def swap_stake_extrinsic(
259269
wallet=wallet,
260270
wait_for_inclusion=wait_for_inclusion,
261271
wait_for_finalization=wait_for_finalization,
272+
period=period,
262273
)
263274

264275
if success:
@@ -309,6 +320,7 @@ async def move_stake_extrinsic(
309320
amount: Balance,
310321
wait_for_inclusion: bool = True,
311322
wait_for_finalization: bool = False,
323+
period: Optional[int] = None,
312324
) -> bool:
313325
"""
314326
Moves stake from one hotkey to another within subnets in the Bittensor network.
@@ -323,6 +335,9 @@ async def move_stake_extrinsic(
323335
amount (Balance): The amount of stake to move as a `Balance` object.
324336
wait_for_inclusion (bool): If True, waits for transaction inclusion in a block. Defaults to True.
325337
wait_for_finalization (bool): If True, waits for transaction finalization. Defaults to False.
338+
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
339+
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
340+
You can think of it as an expiration date for the transaction.
326341
327342
Returns:
328343
bool: True if the move was successful, False otherwise.
@@ -331,7 +346,7 @@ async def move_stake_extrinsic(
331346

332347
# Check sufficient stake
333348
stake_in_origin, stake_in_destination = await _get_stake_in_origin_and_dest(
334-
subtensor,
349+
subtensor=subtensor,
335350
origin_hotkey_ss58=origin_hotkey,
336351
destination_hotkey_ss58=destination_hotkey,
337352
origin_coldkey_ss58=wallet.coldkeypub.ss58_address,
@@ -369,6 +384,7 @@ async def move_stake_extrinsic(
369384
wallet=wallet,
370385
wait_for_inclusion=wait_for_inclusion,
371386
wait_for_finalization=wait_for_finalization,
387+
period=period,
372388
)
373389

374390
if success:
@@ -379,7 +395,7 @@ async def move_stake_extrinsic(
379395

380396
# Get updated stakes
381397
origin_stake, dest_stake = await _get_stake_in_origin_and_dest(
382-
subtensor,
398+
subtensor=subtensor,
383399
origin_hotkey_ss58=origin_hotkey,
384400
destination_hotkey_ss58=destination_hotkey,
385401
origin_coldkey_ss58=wallet.coldkeypub.ss58_address,

0 commit comments

Comments
 (0)