Skip to content

Commit b855e8e

Browse files
authored
Merge pull request #3020 from opentensor/fix/thewhaleking/broken-e2e-tests
Fixes broken e2e tests
2 parents 245c64c + bfe5a0e commit b855e8e

18 files changed

+265
-80
lines changed

bittensor/core/async_subtensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5548,7 +5548,7 @@ async def unstake(
55485548
self,
55495549
wallet: "Wallet",
55505550
hotkey_ss58: Optional[str] = None,
5551-
netuid: Optional[int] = None,
5551+
netuid: Optional[int] = None, # TODO why is this optional?
55525552
amount: Optional[Balance] = None,
55535553
wait_for_inclusion: bool = True,
55545554
wait_for_finalization: bool = False,

bittensor/core/extrinsics/asyncex/registration.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import asyncio
1111
from typing import Optional, Union, TYPE_CHECKING
1212

13+
from bittensor.core.extrinsics.asyncex.utils import get_extrinsic_fee
1314
from bittensor.utils import unlock_key
1415
from bittensor.utils.btlogging import logging
1516
from bittensor.utils.registration import log_no_torch_error, create_pow_async, torch
@@ -57,6 +58,12 @@ async def _do_burned_register(
5758
"hotkey": wallet.hotkey.ss58_address,
5859
},
5960
)
61+
fee = await get_extrinsic_fee(
62+
subtensor=subtensor, call=call, keypair=wallet.coldkeypub
63+
)
64+
logging.info(
65+
f"The registration fee for SN #[blue]{netuid}[/blue] is [blue]{fee}[/blue]."
66+
)
6067
return await subtensor.sign_and_send_extrinsic(
6168
call=call,
6269
wallet=wallet,
@@ -127,7 +134,6 @@ async def burned_register_extrinsic(
127134
return True
128135

129136
logging.debug(":satellite: [magenta]Recycling TAO for Registration...[/magenta]")
130-
logging.info(f"Recycling {recycle_amount} to register on subnet:{netuid}")
131137

132138
success, err_msg = await _do_burned_register(
133139
subtensor=subtensor,

bittensor/core/extrinsics/asyncex/unstaking.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Optional, TYPE_CHECKING
33

44
from async_substrate_interface.errors import SubstrateRequestException
5-
5+
from bittensor.core.extrinsics.asyncex.utils import get_extrinsic_fee
66
from bittensor.core.extrinsics.utils import get_old_stakes
77
from bittensor.utils import unlock_key, format_error_message
88
from bittensor.utils.balance import Balance
@@ -114,14 +114,14 @@ async def unstake_extrinsic(
114114
else:
115115
price_with_tolerance = base_price * (1 - rate_tolerance)
116116

117-
logging.info(
117+
logging_info = (
118118
f":satellite: [magenta]Safe Unstaking from:[/magenta] "
119119
f"netuid: [green]{netuid}[/green], amount: [green]{unstaking_balance}[/green], "
120120
f"tolerance percentage: [green]{rate_tolerance * 100}%[/green], "
121121
f"price limit: [green]{price_with_tolerance}[/green], "
122122
f"original price: [green]{base_price}[/green], "
123123
f"with partial unstake: [green]{allow_partial_stake}[/green] "
124-
f"on [blue]{subtensor.network}[/blue][magenta]...[/magenta]"
124+
f"on [blue]{subtensor.network}[/blue]"
125125
)
126126

127127
limit_price = Balance.from_tao(price_with_tolerance).rao
@@ -133,10 +133,10 @@ async def unstake_extrinsic(
133133
)
134134
call_function = "remove_stake_limit"
135135
else:
136-
logging.info(
136+
logging_info = (
137137
f":satellite: [magenta]Unstaking from:[/magenta] "
138138
f"netuid: [green]{netuid}[/green], amount: [green]{unstaking_balance}[/green] "
139-
f"on [blue]{subtensor.network}[/blue][magenta]...[/magenta]"
139+
f"on [blue]{subtensor.network}[/blue]"
140140
)
141141
call_function = "remove_stake"
142142

@@ -145,6 +145,10 @@ async def unstake_extrinsic(
145145
call_function=call_function,
146146
call_params=call_params,
147147
)
148+
fee = await get_extrinsic_fee(
149+
subtensor=subtensor, call=call, keypair=wallet.coldkeypub, netuid=netuid
150+
)
151+
logging.info(f"{logging_info} for fee [blue]{fee}[/blue][magenta]...[/magenta]")
148152
success, message = await subtensor.sign_and_send_extrinsic(
149153
call=call,
150154
wallet=wallet,
@@ -381,10 +385,6 @@ async def unstake_multiple_extrinsic(
381385
continue
382386

383387
try:
384-
logging.info(
385-
f"Unstaking [blue]{unstaking_balance}[/blue] from hotkey: [magenta]{hotkey_ss58}[/magenta] on netuid: "
386-
f"[blue]{netuid}[/blue]"
387-
)
388388
call = await subtensor.substrate.compose_call(
389389
call_module="SubtensorModule",
390390
call_function="remove_stake",
@@ -394,6 +394,13 @@ async def unstake_multiple_extrinsic(
394394
"netuid": netuid,
395395
},
396396
)
397+
fee = await get_extrinsic_fee(
398+
subtensor=subtensor, call=call, keypair=wallet.coldkeypub, netuid=netuid
399+
)
400+
logging.info(
401+
f"Unstaking [blue]{unstaking_balance}[/blue] from hotkey: [magenta]{hotkey_ss58}[/magenta] on netuid: "
402+
f"[blue]{netuid}[/blue] for fee [blue]{fee}[/blue]"
403+
)
397404

398405
staking_response, err_msg = await subtensor.sign_and_send_extrinsic(
399406
call=call,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from typing import TYPE_CHECKING, Optional
2+
3+
from bittensor.utils.balance import Balance
4+
5+
if TYPE_CHECKING:
6+
from scalecodec import GenericCall
7+
from bittensor_wallet import Keypair
8+
from bittensor.core.async_subtensor import AsyncSubtensor
9+
10+
11+
async def get_extrinsic_fee(
12+
subtensor: "AsyncSubtensor",
13+
call: "GenericCall",
14+
keypair: "Keypair",
15+
netuid: Optional[int] = None,
16+
):
17+
"""
18+
Get extrinsic fee for a given extrinsic call and keypair for a given SN's netuid.
19+
20+
Arguments:
21+
subtensor: The Subtensor instance.
22+
netuid: The SN's netuid.
23+
call: The extrinsic call.
24+
keypair: The keypair associated with the extrinsic.
25+
26+
Returns:
27+
Balance object representing the extrinsic fee in RAO.
28+
"""
29+
payment_info = await subtensor.substrate.get_payment_info(
30+
call=call, keypair=keypair
31+
)
32+
return Balance.from_rao(amount=payment_info["partial_fee"]).set_unit(
33+
netuid=netuid or 0
34+
)

bittensor/core/extrinsics/registration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import time
1010
from typing import Optional, Union, TYPE_CHECKING
1111

12+
from bittensor.core.extrinsics.utils import get_extrinsic_fee
1213
from bittensor.utils import unlock_key
1314
from bittensor.utils.btlogging import logging
1415
from bittensor.utils.registration import create_pow, log_no_torch_error, torch
@@ -56,6 +57,10 @@ def _do_burned_register(
5657
"hotkey": wallet.hotkey.ss58_address,
5758
},
5859
)
60+
fee = get_extrinsic_fee(subtensor=subtensor, call=call, keypair=wallet.coldkeypub)
61+
logging.info(
62+
f"The registration fee for SN #[blue]{netuid}[/blue] is [blue]{fee}[/blue]."
63+
)
5964
return subtensor.sign_and_send_extrinsic(
6065
call=call,
6166
wallet=wallet,
@@ -197,6 +202,7 @@ def _do_pow_register(
197202
"coldkey": wallet.coldkeypub.ss58_address,
198203
},
199204
)
205+
logging.debug(":satellite: [magenta]Sending POW Register Extrinsic...[/magenta]")
200206
return subtensor.sign_and_send_extrinsic(
201207
call=call,
202208
wallet=wallet,

bittensor/core/extrinsics/unstaking.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional, TYPE_CHECKING
22

33
from async_substrate_interface.errors import SubstrateRequestException
4+
from bittensor.core.extrinsics.utils import get_extrinsic_fee
45

56
from bittensor.core.extrinsics.utils import get_old_stakes
67
from bittensor.utils import unlock_key, format_error_message
@@ -112,14 +113,14 @@ def unstake_extrinsic(
112113
else:
113114
price_with_tolerance = base_price * (1 - rate_tolerance)
114115

115-
logging.info(
116+
logging_info = (
116117
f":satellite: [magenta]Safe Unstaking from:[/magenta] "
117118
f"netuid: [green]{netuid}[/green], amount: [green]{unstaking_balance}[/green], "
118119
f"tolerance percentage: [green]{rate_tolerance * 100}%[/green], "
119120
f"price limit: [green]{price_with_tolerance}[/green], "
120121
f"original price: [green]{base_price}[/green], "
121122
f"with partial unstake: [green]{allow_partial_stake}[/green] "
122-
f"on [blue]{subtensor.network}[/blue][magenta]...[/magenta]"
123+
f"on [blue]{subtensor.network}[/blue]"
123124
)
124125

125126
limit_price = Balance.from_tao(price_with_tolerance).rao
@@ -131,10 +132,10 @@ def unstake_extrinsic(
131132
)
132133
call_function = "remove_stake_limit"
133134
else:
134-
logging.info(
135+
logging_info = (
135136
f":satellite: [magenta]Unstaking from:[/magenta] "
136137
f"netuid: [green]{netuid}[/green], amount: [green]{unstaking_balance}[/green] "
137-
f"on [blue]{subtensor.network}[/blue][magenta]...[/magenta]"
138+
f"on [blue]{subtensor.network}[/blue]"
138139
)
139140
call_function = "remove_stake"
140141

@@ -143,6 +144,10 @@ def unstake_extrinsic(
143144
call_function=call_function,
144145
call_params=call_params,
145146
)
147+
fee = get_extrinsic_fee(
148+
subtensor=subtensor, netuid=netuid, call=call, keypair=wallet.coldkeypub
149+
)
150+
logging.info(f"{logging_info} for fee [blue]{fee}[/blue][magenta]...[/magenta]")
146151

147152
success, message = subtensor.sign_and_send_extrinsic(
148153
call=call,
@@ -372,9 +377,6 @@ def unstake_multiple_extrinsic(
372377
continue
373378

374379
try:
375-
logging.info(
376-
f"Unstaking [blue]{unstaking_balance}[/blue] from [magenta]{hotkey_ss58}[/magenta] on [blue]{netuid}[/blue]"
377-
)
378380
call = subtensor.substrate.compose_call(
379381
call_module="SubtensorModule",
380382
call_function="remove_stake",
@@ -384,6 +386,14 @@ def unstake_multiple_extrinsic(
384386
"netuid": netuid,
385387
},
386388
)
389+
fee = get_extrinsic_fee(
390+
subtensor=subtensor, netuid=netuid, call=call, keypair=wallet.coldkeypub
391+
)
392+
logging.info(
393+
f"Unstaking [blue]{unstaking_balance}[/blue] from hotkey: [magenta]{hotkey_ss58}[/magenta] on netuid: "
394+
f"[blue]{netuid}[/blue] for fee [blue]{fee}[/blue]"
395+
)
396+
387397
staking_response, err_msg = subtensor.sign_and_send_extrinsic(
388398
call=call,
389399
wallet=wallet,

bittensor/core/extrinsics/utils.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
"""Module with helper functions for extrinsics."""
22

3-
from typing import TYPE_CHECKING
3+
from typing import TYPE_CHECKING, Optional
44

55
from bittensor.utils.balance import Balance
66

77
if TYPE_CHECKING:
8-
from bittensor_wallet import Wallet
8+
from scalecodec import GenericCall
9+
from bittensor_wallet import Wallet, Keypair
910
from bittensor.core.chain_data import StakeInfo
11+
from bittensor.core.subtensor import Subtensor
1012

1113

1214
def get_old_stakes(
@@ -42,3 +44,27 @@ def get_old_stakes(
4244
)
4345
for hotkey_ss58, netuid in zip(hotkey_ss58s, netuids)
4446
]
47+
48+
49+
def get_extrinsic_fee(
50+
call: "GenericCall",
51+
keypair: "Keypair",
52+
subtensor: "Subtensor",
53+
netuid: Optional[int] = None,
54+
):
55+
"""
56+
Get extrinsic fee for a given extrinsic call and keypair for a given SN's netuid.
57+
58+
Arguments:
59+
subtensor: The Subtensor instance.
60+
call: The extrinsic call.
61+
keypair: The keypair associated with the extrinsic.
62+
netuid: The SN's netuid.
63+
64+
Returns:
65+
Balance object representing the extrinsic fee in RAO.
66+
"""
67+
payment_info = subtensor.substrate.get_payment_info(call=call, keypair=keypair)
68+
return Balance.from_rao(amount=payment_info["partial_fee"]).set_unit(
69+
netuid=netuid or 0
70+
)

bittensor/core/subtensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4368,7 +4368,7 @@ def unstake(
43684368
self,
43694369
wallet: "Wallet",
43704370
hotkey_ss58: Optional[str] = None,
4371-
netuid: Optional[int] = None,
4371+
netuid: Optional[int] = None, # TODO why is this optional?
43724372
amount: Optional[Balance] = None,
43734373
wait_for_inclusion: bool = True,
43744374
wait_for_finalization: bool = False,

0 commit comments

Comments
 (0)