Skip to content

Commit 33aebe6

Browse files
committed
apply default era.period to all subtensor extrinsic calls
1 parent fb4c478 commit 33aebe6

File tree

9 files changed

+127
-136
lines changed

9 files changed

+127
-136
lines changed

bittensor/core/async_subtensor.py

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,11 @@ async def bonds(
956956
return b_map
957957

958958
async def commit(
959-
self, wallet: "Wallet", netuid: int, data: str, period: Optional[int] = None
959+
self,
960+
wallet: "Wallet",
961+
netuid: int,
962+
data: str,
963+
period: Optional[int] = DEFAULT_PERIOD,
960964
) -> bool:
961965
"""Commits arbitrary data to the Bittensor network by publishing metadata.
962966
@@ -4049,7 +4053,7 @@ async def set_reveal_commitment(
40494053
data: str,
40504054
blocks_until_reveal: int = 360,
40514055
block_time: Union[int, float] = 12,
4052-
period: Optional[int] = None,
4056+
period: Optional[int] = DEFAULT_PERIOD,
40534057
) -> tuple[bool, int]:
40544058
"""
40554059
Commits arbitrary data to the Bittensor network by publishing metadata.
@@ -4443,7 +4447,7 @@ async def sign_and_send_extrinsic(
44434447
wait_for_finalization: bool = False,
44444448
sign_with: str = "coldkey",
44454449
use_nonce: bool = False,
4446-
period: Optional[int] = None,
4450+
period: Optional[int] = DEFAULT_PERIOD,
44474451
nonce_key: str = "hotkey",
44484452
raise_error: bool = False,
44494453
) -> tuple[bool, str]:
@@ -4476,13 +4480,7 @@ async def sign_and_send_extrinsic(
44764480
f"'sign_with' must be either 'coldkey', 'hotkey' or 'coldkeypub', not '{sign_with}'"
44774481
)
44784482
signing_keypair = getattr(wallet, sign_with)
4479-
extrinsic_data = {
4480-
"call": call,
4481-
"keypair": signing_keypair,
4482-
"era": {
4483-
"period": period or DEFAULT_PERIOD,
4484-
},
4485-
}
4483+
extrinsic_data = {"call": call, "keypair": signing_keypair}
44864484
if use_nonce:
44874485
if nonce_key not in possible_keys:
44884486
raise AttributeError(
@@ -4493,6 +4491,9 @@ async def sign_and_send_extrinsic(
44934491
)
44944492
extrinsic_data["nonce"] = next_nonce
44954493

4494+
if period is not None:
4495+
extrinsic_data["era"] = {"period": period}
4496+
44964497
extrinsic = await self.substrate.create_signed_extrinsic(**extrinsic_data)
44974498
try:
44984499
response = await self.substrate.submit_extrinsic(
@@ -4533,7 +4534,7 @@ async def add_stake(
45334534
safe_staking: bool = False,
45344535
allow_partial_stake: bool = False,
45354536
rate_tolerance: float = 0.005,
4536-
period: Optional[int] = None,
4537+
period: Optional[int] = DEFAULT_PERIOD,
45374538
) -> bool:
45384539
"""
45394540
Adds a stake from the specified wallet to the neuron identified by the SS58 address of its hotkey in specified
@@ -4591,7 +4592,7 @@ async def add_liquidity(
45914592
hotkey: Optional[str] = None,
45924593
wait_for_inclusion: bool = True,
45934594
wait_for_finalization: bool = False,
4594-
period: Optional[int] = None,
4595+
period: Optional[int] = DEFAULT_PERIOD,
45954596
) -> tuple[bool, str]:
45964597
"""
45974598
Adds liquidity to the specified price range.
@@ -4674,7 +4675,7 @@ async def burned_register(
46744675
netuid: int,
46754676
wait_for_inclusion: bool = False,
46764677
wait_for_finalization: bool = True,
4677-
period: Optional[int] = None,
4678+
period: Optional[int] = DEFAULT_PERIOD,
46784679
) -> bool:
46794680
"""
46804681
Registers a neuron on the Bittensor network by recycling TAO. This method of registration involves recycling
@@ -4723,7 +4724,7 @@ async def commit_weights(
47234724
wait_for_inclusion: bool = False,
47244725
wait_for_finalization: bool = False,
47254726
max_retries: int = 5,
4726-
period: Optional[int] = 16,
4727+
period: Optional[int] = DEFAULT_PERIOD,
47274728
mechid: int = 0,
47284729
) -> tuple[bool, str]:
47294730
"""
@@ -4798,7 +4799,7 @@ async def modify_liquidity(
47984799
hotkey: Optional[str] = None,
47994800
wait_for_inclusion: bool = True,
48004801
wait_for_finalization: bool = False,
4801-
period: Optional[int] = None,
4802+
period: Optional[int] = DEFAULT_PERIOD,
48024803
) -> tuple[bool, str]:
48034804
"""Modifies liquidity in liquidity position by adding or removing liquidity from it.
48044805
@@ -4871,7 +4872,7 @@ async def move_stake(
48714872
amount: Optional[Balance] = None,
48724873
wait_for_inclusion: bool = True,
48734874
wait_for_finalization: bool = False,
4874-
period: Optional[int] = None,
4875+
period: Optional[int] = DEFAULT_PERIOD,
48754876
move_all_stake: bool = False,
48764877
) -> bool:
48774878
"""
@@ -4923,7 +4924,7 @@ async def register(
49234924
num_processes: Optional[int] = None,
49244925
update_interval: Optional[int] = None,
49254926
log_verbose: bool = False,
4926-
period: Optional[int] = None,
4927+
period: Optional[int] = DEFAULT_PERIOD,
49274928
):
49284929
"""
49294930
Registers a neuron on the Bittensor network using the provided wallet.
@@ -4977,7 +4978,7 @@ async def register_subnet(
49774978
wallet: "Wallet",
49784979
wait_for_inclusion: bool = False,
49794980
wait_for_finalization: bool = True,
4980-
period: Optional[int] = None,
4981+
period: Optional[int] = DEFAULT_PERIOD,
49814982
) -> bool:
49824983
"""
49834984
Registers a new subnetwork on the Bittensor network.
@@ -5011,7 +5012,7 @@ async def remove_liquidity(
50115012
hotkey: Optional[str] = None,
50125013
wait_for_inclusion: bool = True,
50135014
wait_for_finalization: bool = False,
5014-
period: Optional[int] = None,
5015+
period: Optional[int] = DEFAULT_PERIOD,
50155016
) -> tuple[bool, str]:
50165017
"""Remove liquidity and credit balances back to wallet's hotkey stake.
50175018
@@ -5059,7 +5060,7 @@ async def reveal_weights(
50595060
wait_for_inclusion: bool = False,
50605061
wait_for_finalization: bool = False,
50615062
max_retries: int = 5,
5062-
period: Optional[int] = None,
5063+
period: Optional[int] = DEFAULT_PERIOD,
50635064
mechid: int = 0,
50645065
) -> tuple[bool, str]:
50655066
"""
@@ -5124,7 +5125,7 @@ async def root_set_pending_childkey_cooldown(
51245125
cooldown: int,
51255126
wait_for_inclusion: bool = True,
51265127
wait_for_finalization: bool = True,
5127-
period: Optional[int] = None,
5128+
period: Optional[int] = DEFAULT_PERIOD,
51285129
) -> tuple[bool, str]:
51295130
"""Sets the pending childkey cooldown.
51305131
@@ -5160,7 +5161,7 @@ async def root_register(
51605161
block_hash: Optional[str] = None,
51615162
wait_for_inclusion: bool = True,
51625163
wait_for_finalization: bool = True,
5163-
period: Optional[int] = None,
5164+
period: Optional[int] = DEFAULT_PERIOD,
51645165
) -> bool:
51655166
"""
51665167
Register neuron by recycling some TAO.
@@ -5195,7 +5196,7 @@ async def root_set_weights(
51955196
version_key: int = 0,
51965197
wait_for_inclusion: bool = True,
51975198
wait_for_finalization: bool = True,
5198-
period: Optional[int] = None,
5199+
period: Optional[int] = DEFAULT_PERIOD,
51995200
) -> bool:
52005201
"""
52015202
Set weights for the root network.
@@ -5233,7 +5234,7 @@ async def set_auto_stake(
52335234
wallet: "Wallet",
52345235
netuid: int,
52355236
hotkey_ss58: str,
5236-
period: Optional[int] = None,
5237+
period: Optional[int] = DEFAULT_PERIOD,
52375238
raise_error: bool = False,
52385239
wait_for_inclusion: bool = True,
52395240
wait_for_finalization: bool = True,
@@ -5277,7 +5278,7 @@ async def set_children(
52775278
wait_for_inclusion: bool = True,
52785279
wait_for_finalization: bool = True,
52795280
raise_error: bool = False,
5280-
period: Optional[int] = None,
5281+
period: Optional[int] = DEFAULT_PERIOD,
52815282
) -> tuple[bool, str]:
52825283
"""
52835284
Allows a coldkey to set children-keys.
@@ -5331,7 +5332,7 @@ async def set_delegate_take(
53315332
wait_for_inclusion: bool = True,
53325333
wait_for_finalization: bool = True,
53335334
raise_error: bool = False,
5334-
period: Optional[int] = None,
5335+
period: Optional[int] = DEFAULT_PERIOD,
53355336
) -> tuple[bool, str]:
53365337
"""
53375338
Sets the delegate 'take' percentage for a neuron identified by its hotkey.
@@ -5414,7 +5415,7 @@ async def set_subnet_identity(
54145415
subnet_identity: SubnetIdentity,
54155416
wait_for_inclusion: bool = False,
54165417
wait_for_finalization: bool = True,
5417-
period: Optional[int] = None,
5418+
period: Optional[int] = DEFAULT_PERIOD,
54185419
) -> tuple[bool, str]:
54195420
"""
54205421
Sets the identity of a subnet for a specific wallet and network.
@@ -5464,7 +5465,7 @@ async def set_weights(
54645465
wait_for_finalization: bool = False,
54655466
max_retries: int = 5,
54665467
block_time: float = 12.0,
5467-
period: Optional[int] = 8,
5468+
period: Optional[int] = DEFAULT_PERIOD,
54685469
mechid: int = 0,
54695470
commit_reveal_version: int = 4,
54705471
):
@@ -5589,7 +5590,7 @@ async def serve_axon(
55895590
wait_for_inclusion: bool = False,
55905591
wait_for_finalization: bool = True,
55915592
certificate: Optional[Certificate] = None,
5592-
period: Optional[int] = None,
5593+
period: Optional[int] = DEFAULT_PERIOD,
55935594
) -> bool:
55945595
"""
55955596
Registers an ``Axon`` serving endpoint on the Bittensor network for a specific neuron. This function is used to
@@ -5627,7 +5628,7 @@ async def start_call(
56275628
netuid: int,
56285629
wait_for_inclusion: bool = True,
56295630
wait_for_finalization: bool = False,
5630-
period: Optional[int] = None,
5631+
period: Optional[int] = DEFAULT_PERIOD,
56315632
) -> tuple[bool, str]:
56325633
"""
56335634
Submits a start_call extrinsic to the blockchain, to trigger the start call process for a subnet (used to start
@@ -5668,7 +5669,7 @@ async def swap_stake(
56685669
safe_staking: bool = False,
56695670
allow_partial_stake: bool = False,
56705671
rate_tolerance: float = 0.005,
5671-
period: Optional[int] = None,
5672+
period: Optional[int] = DEFAULT_PERIOD,
56725673
) -> bool:
56735674
"""
56745675
Moves stake between subnets while keeping the same coldkey-hotkey pair ownership.
@@ -5727,7 +5728,7 @@ async def toggle_user_liquidity(
57275728
enable: bool,
57285729
wait_for_inclusion: bool = True,
57295730
wait_for_finalization: bool = False,
5730-
period: Optional[int] = None,
5731+
period: Optional[int] = DEFAULT_PERIOD,
57315732
) -> tuple[bool, str]:
57325733
"""Allow to toggle user liquidity for specified subnet.
57335734
@@ -5767,7 +5768,7 @@ async def transfer(
57675768
wait_for_inclusion: bool = True,
57685769
wait_for_finalization: bool = False,
57695770
keep_alive: bool = True,
5770-
period: Optional[int] = None,
5771+
period: Optional[int] = DEFAULT_PERIOD,
57715772
) -> bool:
57725773
"""
57735774
Transfer token of amount to destination.
@@ -5810,7 +5811,7 @@ async def transfer_stake(
58105811
amount: Balance,
58115812
wait_for_inclusion: bool = True,
58125813
wait_for_finalization: bool = False,
5813-
period: Optional[int] = None,
5814+
period: Optional[int] = DEFAULT_PERIOD,
58145815
) -> bool:
58155816
"""
58165817
Transfers stake from one subnet to another while changing the coldkey owner.
@@ -5856,7 +5857,7 @@ async def unstake(
58565857
safe_staking: bool = False,
58575858
allow_partial_stake: bool = False,
58585859
rate_tolerance: float = 0.005,
5859-
period: Optional[int] = None,
5860+
period: Optional[int] = DEFAULT_PERIOD,
58605861
unstake_all: bool = False,
58615862
) -> bool:
58625863
"""
@@ -5913,7 +5914,7 @@ async def unstake_all(
59135914
rate_tolerance: Optional[float] = 0.005,
59145915
wait_for_inclusion: bool = True,
59155916
wait_for_finalization: bool = False,
5916-
period: Optional[int] = None,
5917+
period: Optional[int] = DEFAULT_PERIOD,
59175918
) -> tuple[bool, str]:
59185919
"""Unstakes all TAO/Alpha associated with a hotkey from the specified subnets on the Bittensor network.
59195920
@@ -5997,7 +5998,7 @@ async def unstake_multiple(
59975998
amounts: Optional[list[Balance]] = None,
59985999
wait_for_inclusion: bool = True,
59996000
wait_for_finalization: bool = False,
6000-
period: Optional[int] = None,
6001+
period: Optional[int] = DEFAULT_PERIOD,
60016002
unstake_all: bool = False,
60026003
) -> bool:
60036004
"""

bittensor/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
SS58_ADDRESS_LENGTH = 48
7272

7373
# Default period for extrinsic Era
74-
DEFAULT_PERIOD = 16
74+
DEFAULT_PERIOD = 32
7575

7676
# Block Explorers map network to explorer url
7777
# Must all be polkadotjs explorer urls

0 commit comments

Comments
 (0)