Skip to content

Commit f0745fe

Browse files
authored
Merge pull request #3234 from opentensor/feat/roman/start_call_delay_hyperparameter
Add `start_call_delay_hyperparameter` support
2 parents 264d1b3 + f73c629 commit f0745fe

File tree

10 files changed

+334
-25
lines changed

10 files changed

+334
-25
lines changed

bittensor/core/async_subtensor.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4306,6 +4306,35 @@ async def get_stake_weight(
43064306
)
43074307
return [u16_normalized_float(w) for w in result]
43084308

4309+
async def get_start_call_delay(
4310+
self,
4311+
block: Optional[int] = None,
4312+
block_hash: Optional[str] = None,
4313+
reuse_block: bool = False,
4314+
) -> int:
4315+
"""
4316+
Retrieves the start call delay in blocks.
4317+
4318+
Parameters:
4319+
block: The blockchain block number for the query.
4320+
block_hash: The blockchain block_hash of the block id.
4321+
reuse_block: Whether to reuse the last-used block hash.
4322+
4323+
Return:
4324+
Amount of blocks after the start call can be executed.
4325+
"""
4326+
return cast(
4327+
int,
4328+
(
4329+
await self.query_subtensor(
4330+
name="StartCallDelay",
4331+
block=block,
4332+
block_hash=block_hash,
4333+
reuse_block=reuse_block,
4334+
)
4335+
),
4336+
)
4337+
43094338
async def get_subnet_burn_cost(
43104339
self,
43114340
block: Optional[int] = None,
@@ -4985,19 +5014,17 @@ async def is_in_admin_freeze_window(
49855014
async def is_fast_blocks(self) -> bool:
49865015
"""Checks if the node is running with fast blocks enabled.
49875016
4988-
Fast blocks have a block time of 10 seconds, compared to the standard 12-second block time. This affects
5017+
Fast blocks have a block time of 0.25 seconds, compared to the standard 12-second block time. This affects
49895018
transaction timing and network synchronization.
49905019
49915020
Returns:
4992-
`True` if fast blocks are enabled (10-second block time), `False` otherwise (12-second block time).
5021+
`True` if fast blocks are enabled, `False` otherwise.
49935022
49945023
Notes:
49955024
- <https://docs.learnbittensor.org/resources/glossary#fast-blocks>
49965025
49975026
"""
4998-
return (
4999-
await self.query_constant("SubtensorModule", "DurationOfStartCall")
5000-
) == 10
5027+
return await self.get_start_call_delay() == 10
50015028

50025029
async def is_hotkey_delegate(
50035030
self,

bittensor/core/subtensor.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,6 +3540,24 @@ def get_stake_weight(self, netuid: int, block: Optional[int] = None) -> list[flo
35403540
)
35413541
return [u16_normalized_float(w) for w in result]
35423542

3543+
def get_start_call_delay(self, block: Optional[int] = None) -> int:
3544+
"""
3545+
Retrieves the start call delay in blocks.
3546+
3547+
Parameters:
3548+
block: The blockchain block number for the query.
3549+
3550+
Return:
3551+
Amount of blocks after the start call can be executed.
3552+
"""
3553+
return cast(
3554+
int,
3555+
self.query_subtensor(
3556+
name="StartCallDelay",
3557+
block=block,
3558+
),
3559+
)
3560+
35433561
def get_subnet_burn_cost(self, block: Optional[int] = None) -> Optional[Balance]:
35443562
"""
35453563
Retrieves the burn cost for registering a new subnet within the Bittensor network. This cost represents the
@@ -4075,17 +4093,17 @@ def is_in_admin_freeze_window(
40754093
def is_fast_blocks(self) -> bool:
40764094
"""Checks if the node is running with fast blocks enabled.
40774095
4078-
Fast blocks have a block time of 10 seconds, compared to the standard 12-second block time. This affects
4096+
Fast blocks have a block time of 0.25 seconds, compared to the standard 12-second block time. This affects
40794097
transaction timing and network synchronization.
40804098
40814099
Returns:
4082-
`True` if fast blocks are enabled (10-second block time), `False` otherwise (12-second block time).
4100+
`True` if fast blocks are enabled, `False` otherwise.
40834101
40844102
Notes:
40854103
- <https://docs.learnbittensor.org/resources/glossary#fast-blocks>
40864104
40874105
"""
4088-
return self.query_constant("SubtensorModule", "DurationOfStartCall") == 10
4106+
return self.get_start_call_delay() == 10
40894107

40904108
def is_hotkey_delegate(self, hotkey_ss58: str, block: Optional[int] = None) -> bool:
40914109
"""

bittensor/extras/dev_framework/calls/non_sudo_calls.py

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
Note:
1313
Any manual changes will be overwritten the next time the generator is run.
14-
Subtensor spec version: 331
14+
Subtensor spec version: 365
1515
"""
1616

1717
from collections import namedtuple
@@ -42,6 +42,9 @@
4242
ANNOUNCE = namedtuple(
4343
"ANNOUNCE", ["wallet", "pallet", "real", "call_hash"]
4444
) # args: [real: AccountIdLookupOf<T>, call_hash: CallHashOf<T>] | Pallet: Proxy
45+
ANNOUNCE_NEXT_KEY = namedtuple(
46+
"ANNOUNCE_NEXT_KEY", ["wallet", "pallet", "public_key"]
47+
) # args: [public_key: BoundedVec<u8, ConstU32<2048>>] | Pallet: MevShield
4548
APPLY_AUTHORIZED_UPGRADE = namedtuple(
4649
"APPLY_AUTHORIZED_UPGRADE", ["wallet", "pallet", "code"]
4750
) # args: [code: Vec<u8>] | Pallet: System
@@ -118,6 +121,10 @@
118121
BURN_ALPHA = namedtuple(
119122
"BURN_ALPHA", ["wallet", "pallet", "hotkey", "amount", "netuid"]
120123
) # args: [hotkey: T::AccountId, amount: AlphaCurrency, netuid: NetUid] | Pallet: SubtensorModule
124+
CALL = namedtuple(
125+
"CALL",
126+
["wallet", "pallet", "dest", "value", "gas_limit", "storage_deposit_limit", "data"],
127+
) # args: [dest: AccountIdLookupOf<T>, value: BalanceOf<T>, gas_limit: Weight, storage_deposit_limit: Option<<BalanceOf<T> as codec::HasCompact>::Type>, data: Vec<u8>] | Pallet: Contracts
121128
CALL = namedtuple(
122129
"CALL",
123130
[
@@ -135,6 +142,10 @@
135142
"authorization_list",
136143
],
137144
) # args: [source: H160, target: H160, input: Vec<u8>, value: U256, gas_limit: u64, max_fee_per_gas: U256, max_priority_fee_per_gas: Option<U256>, nonce: Option<U256>, access_list: Vec<(H160, Vec<H256>)>, authorization_list: AuthorizationList] | Pallet: EVM
145+
CALL_OLD_WEIGHT = namedtuple(
146+
"CALL_OLD_WEIGHT",
147+
["wallet", "pallet", "dest", "value", "gas_limit", "storage_deposit_limit", "data"],
148+
) # args: [dest: AccountIdLookupOf<T>, value: BalanceOf<T>, gas_limit: OldWeight, storage_deposit_limit: Option<<BalanceOf<T> as codec::HasCompact>::Type>, data: Vec<u8>] | Pallet: Contracts
138149
CANCEL = namedtuple(
139150
"CANCEL", ["wallet", "pallet", "when", "index"]
140151
) # args: [when: BlockNumberFor<T>, index: u32] | Pallet: Scheduler
@@ -152,12 +163,8 @@
152163
"CANCEL_RETRY_NAMED", ["wallet", "pallet", "id"]
153164
) # args: [id: TaskName] | Pallet: Scheduler
154165
CLAIM_ROOT = namedtuple(
155-
"CLAIM_ROOT",
156-
[
157-
"wallet",
158-
"pallet",
159-
],
160-
) # args: [] | Pallet: SubtensorModule
166+
"CLAIM_ROOT", ["wallet", "pallet", "subnets"]
167+
) # args: [subnets: BTreeSet<NetUid>] | Pallet: SubtensorModule
161168
CLEAR_IDENTITY = namedtuple(
162169
"CLEAR_IDENTITY", ["wallet", "pallet", "identified"]
163170
) # args: [identified: T::AccountId] | Pallet: Registry
@@ -242,6 +249,13 @@
242249
DECREASE_TAKE = namedtuple(
243250
"DECREASE_TAKE", ["wallet", "pallet", "hotkey", "take"]
244251
) # args: [hotkey: T::AccountId, take: u16] | Pallet: SubtensorModule
252+
DISABLE_LP = namedtuple(
253+
"DISABLE_LP",
254+
[
255+
"wallet",
256+
"pallet",
257+
],
258+
) # args: [] | Pallet: Swap
245259
DISABLE_WHITELIST = namedtuple(
246260
"DISABLE_WHITELIST", ["wallet", "pallet", "disabled"]
247261
) # args: [disabled: bool] | Pallet: EVM
@@ -328,6 +342,58 @@
328342
INCREASE_TAKE = namedtuple(
329343
"INCREASE_TAKE", ["wallet", "pallet", "hotkey", "take"]
330344
) # args: [hotkey: T::AccountId, take: u16] | Pallet: SubtensorModule
345+
INSTANTIATE = namedtuple(
346+
"INSTANTIATE",
347+
[
348+
"wallet",
349+
"pallet",
350+
"value",
351+
"gas_limit",
352+
"storage_deposit_limit",
353+
"code_hash",
354+
"data",
355+
"salt",
356+
],
357+
) # args: [value: BalanceOf<T>, gas_limit: Weight, storage_deposit_limit: Option<<BalanceOf<T> as codec::HasCompact>::Type>, code_hash: CodeHash<T>, data: Vec<u8>, salt: Vec<u8>] | Pallet: Contracts
358+
INSTANTIATE_OLD_WEIGHT = namedtuple(
359+
"INSTANTIATE_OLD_WEIGHT",
360+
[
361+
"wallet",
362+
"pallet",
363+
"value",
364+
"gas_limit",
365+
"storage_deposit_limit",
366+
"code_hash",
367+
"data",
368+
"salt",
369+
],
370+
) # args: [value: BalanceOf<T>, gas_limit: OldWeight, storage_deposit_limit: Option<<BalanceOf<T> as codec::HasCompact>::Type>, code_hash: CodeHash<T>, data: Vec<u8>, salt: Vec<u8>] | Pallet: Contracts
371+
INSTANTIATE_WITH_CODE = namedtuple(
372+
"INSTANTIATE_WITH_CODE",
373+
[
374+
"wallet",
375+
"pallet",
376+
"value",
377+
"gas_limit",
378+
"storage_deposit_limit",
379+
"code",
380+
"data",
381+
"salt",
382+
],
383+
) # args: [value: BalanceOf<T>, gas_limit: Weight, storage_deposit_limit: Option<<BalanceOf<T> as codec::HasCompact>::Type>, code: Vec<u8>, data: Vec<u8>, salt: Vec<u8>] | Pallet: Contracts
384+
INSTANTIATE_WITH_CODE_OLD_WEIGHT = namedtuple(
385+
"INSTANTIATE_WITH_CODE_OLD_WEIGHT",
386+
[
387+
"wallet",
388+
"pallet",
389+
"value",
390+
"gas_limit",
391+
"storage_deposit_limit",
392+
"code",
393+
"data",
394+
"salt",
395+
],
396+
) # args: [value: BalanceOf<T>, gas_limit: OldWeight, storage_deposit_limit: Option<<BalanceOf<T> as codec::HasCompact>::Type>, code: Vec<u8>, data: Vec<u8>, salt: Vec<u8>] | Pallet: Contracts
331397
KILL_PREFIX = namedtuple(
332398
"KILL_PREFIX", ["wallet", "pallet", "prefix", "subkeys"]
333399
) # args: [prefix: Key, subkeys: u32] | Pallet: System
@@ -338,6 +404,12 @@
338404
KILL_STORAGE = namedtuple(
339405
"KILL_STORAGE", ["wallet", "pallet", "keys"]
340406
) # args: [keys: Vec<Key>] | Pallet: System
407+
MARK_DECRYPTION_FAILED = namedtuple(
408+
"MARK_DECRYPTION_FAILED", ["wallet", "pallet", "id", "reason"]
409+
) # args: [id: T::Hash, reason: BoundedVec<u8, ConstU32<256>>] | Pallet: MevShield
410+
MIGRATE = namedtuple(
411+
"MIGRATE", ["wallet", "pallet", "weight_limit"]
412+
) # args: [weight_limit: Weight] | Pallet: Contracts
341413
MODIFY_POSITION = namedtuple(
342414
"MODIFY_POSITION",
343415
["wallet", "pallet", "hotkey", "netuid", "position_id", "liquidity_delta"],
@@ -420,6 +492,9 @@
420492
REMOVE_ANNOUNCEMENT = namedtuple(
421493
"REMOVE_ANNOUNCEMENT", ["wallet", "pallet", "real", "call_hash"]
422494
) # args: [real: AccountIdLookupOf<T>, call_hash: CallHashOf<T>] | Pallet: Proxy
495+
REMOVE_CODE = namedtuple(
496+
"REMOVE_CODE", ["wallet", "pallet", "code_hash"]
497+
) # args: [code_hash: CodeHash<T>] | Pallet: Contracts
423498
REMOVE_KEY = namedtuple(
424499
"REMOVE_KEY",
425500
[
@@ -557,6 +632,9 @@
557632
SET_CODE = namedtuple(
558633
"SET_CODE", ["wallet", "pallet", "code"]
559634
) # args: [code: Vec<u8>] | Pallet: System
635+
SET_CODE = namedtuple(
636+
"SET_CODE", ["wallet", "pallet", "dest", "code_hash"]
637+
) # args: [dest: AccountIdLookupOf<T>, code_hash: CodeHash<T>] | Pallet: Contracts
560638
SET_CODE_WITHOUT_CHECKS = namedtuple(
561639
"SET_CODE_WITHOUT_CHECKS", ["wallet", "pallet", "code"]
562640
) # args: [code: Vec<u8>] | Pallet: System
@@ -645,6 +723,9 @@
645723
START_CALL = namedtuple(
646724
"START_CALL", ["wallet", "pallet", "netuid"]
647725
) # args: [netuid: NetUid] | Pallet: SubtensorModule
726+
SUBMIT_ENCRYPTED = namedtuple(
727+
"SUBMIT_ENCRYPTED", ["wallet", "pallet", "commitment", "ciphertext"]
728+
) # args: [commitment: T::Hash, ciphertext: BoundedVec<u8, ConstU32<8192>>] | Pallet: MevShield
648729
SUDO = namedtuple(
649730
"SUDO", ["wallet", "pallet", "call"]
650731
) # args: [call: Box<<T as Config>::RuntimeCall>] | Pallet: Sudo
@@ -742,6 +823,9 @@
742823
UPGRADE_ACCOUNTS = namedtuple(
743824
"UPGRADE_ACCOUNTS", ["wallet", "pallet", "who"]
744825
) # args: [who: Vec<T::AccountId>] | Pallet: Balances
826+
UPLOAD_CODE = namedtuple(
827+
"UPLOAD_CODE", ["wallet", "pallet", "code", "storage_deposit_limit", "determinism"]
828+
) # args: [code: Vec<u8>, storage_deposit_limit: Option<<BalanceOf<T> as codec::HasCompact>::Type>, determinism: Determinism] | Pallet: Contracts
745829
WITHDRAW = namedtuple(
746830
"WITHDRAW", ["wallet", "pallet", "address", "value"]
747831
) # args: [address: H160, value: BalanceOf<T>] | Pallet: EVM

bittensor/extras/dev_framework/calls/pallets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
""" "
2-
Subtensor spec version: 331
2+
Subtensor spec version: 365
33
"""
44

55
System = "System"
@@ -23,3 +23,5 @@
2323
Drand = "Drand"
2424
Crowdloan = "Crowdloan"
2525
Swap = "Swap"
26+
Contracts = "Contracts"
27+
MevShield = "MevShield"

bittensor/extras/dev_framework/calls/sudo_calls.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
Note:
1313
Any manual changes will be overwritten the next time the generator is run.
14-
Subtensor spec version: 331
14+
Subtensor spec version: 365
1515
"""
1616

1717
from collections import namedtuple
@@ -149,6 +149,9 @@
149149
SUDO_SET_MIN_DIFFICULTY = namedtuple(
150150
"SUDO_SET_MIN_DIFFICULTY", ["wallet", "pallet", "sudo", "netuid", "min_difficulty"]
151151
) # args: [netuid: NetUid, min_difficulty: u64] | Pallet: AdminUtils
152+
SUDO_SET_MIN_NON_IMMUNE_UIDS = namedtuple(
153+
"SUDO_SET_MIN_NON_IMMUNE_UIDS", ["wallet", "pallet", "sudo", "netuid", "min"]
154+
) # args: [netuid: NetUid, min: u16] | Pallet: AdminUtils
152155
SUDO_SET_NETWORK_IMMUNITY_PERIOD = namedtuple(
153156
"SUDO_SET_NETWORK_IMMUNITY_PERIOD", ["wallet", "pallet", "sudo", "immunity_period"]
154157
) # args: [immunity_period: u64] | Pallet: AdminUtils
@@ -202,6 +205,9 @@
202205
SUDO_SET_STAKE_THRESHOLD = namedtuple(
203206
"SUDO_SET_STAKE_THRESHOLD", ["wallet", "pallet", "sudo", "min_stake"]
204207
) # args: [min_stake: u64] | Pallet: AdminUtils
208+
SUDO_SET_START_CALL_DELAY = namedtuple(
209+
"SUDO_SET_START_CALL_DELAY", ["wallet", "pallet", "sudo", "delay"]
210+
) # args: [delay: u64] | Pallet: AdminUtils
205211
SUDO_SET_SUBNET_LIMIT = namedtuple(
206212
"SUDO_SET_SUBNET_LIMIT", ["wallet", "pallet", "sudo", "max_subnets"]
207213
) # args: [max_subnets: u16] | Pallet: AdminUtils
@@ -218,6 +224,16 @@
218224
"SUDO_SET_SUBTOKEN_ENABLED",
219225
["wallet", "pallet", "sudo", "netuid", "subtoken_enabled"],
220226
) # args: [netuid: NetUid, subtoken_enabled: bool] | Pallet: AdminUtils
227+
SUDO_SET_TAO_FLOW_CUTOFF = namedtuple(
228+
"SUDO_SET_TAO_FLOW_CUTOFF", ["wallet", "pallet", "sudo", "flow_cutoff"]
229+
) # args: [flow_cutoff: I64F64] | Pallet: AdminUtils
230+
SUDO_SET_TAO_FLOW_NORMALIZATION_EXPONENT = namedtuple(
231+
"SUDO_SET_TAO_FLOW_NORMALIZATION_EXPONENT", ["wallet", "pallet", "sudo", "exponent"]
232+
) # args: [exponent: U64F64] | Pallet: AdminUtils
233+
SUDO_SET_TAO_FLOW_SMOOTHING_FACTOR = namedtuple(
234+
"SUDO_SET_TAO_FLOW_SMOOTHING_FACTOR",
235+
["wallet", "pallet", "sudo", "smoothing_factor"],
236+
) # args: [smoothing_factor: u64] | Pallet: AdminUtils
221237
SUDO_SET_TARGET_REGISTRATIONS_PER_INTERVAL = namedtuple(
222238
"SUDO_SET_TARGET_REGISTRATIONS_PER_INTERVAL",
223239
["wallet", "pallet", "sudo", "netuid", "target_registrations_per_interval"],

bittensor/extras/dev_framework/subnet.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,7 @@ def _activate_subnet(
259259
"""Activate subnet."""
260260
self._check_netuid()
261261
current_block = self.s.block
262-
activation_block = self.s.queries.query_constant(
263-
"SubtensorModule", "DurationOfStartCall"
264-
).value
262+
activation_block = self.s.chain.get_start_call_delay()
265263
# added 10 blocks bc 2.5 seconds is not always enough for the chain to update.
266264
self.s.wait_for_block(current_block + activation_block + 1)
267265
response = self.s.subnets.start_call(
@@ -292,11 +290,7 @@ async def _async_activate_subnet(
292290
"""Activate subnet."""
293291
self._check_netuid()
294292
current_block = await self.s.block
295-
activation_block = (
296-
await self.s.queries.query_constant(
297-
"SubtensorModule", "DurationOfStartCall"
298-
)
299-
).value
293+
activation_block = await self.s.chain.get_start_call_delay()
300294
# added 10 blocks bc 2.5 seconds is not always enough for the chain to update.
301295
await self.s.wait_for_block(current_block + activation_block + 1)
302296

bittensor/extras/subtensor_api/chain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def __init__(self, subtensor: Union["_Subtensor", "_AsyncSubtensor"]):
1414
self.get_delegate_identities = subtensor.get_delegate_identities
1515
self.get_existential_deposit = subtensor.get_existential_deposit
1616
self.get_minimum_required_stake = subtensor.get_minimum_required_stake
17+
self.get_start_call_delay = subtensor.get_start_call_delay
1718
self.get_timestamp = subtensor.get_timestamp
1819
self.get_vote_data = subtensor.get_vote_data
1920
self.is_fast_blocks = subtensor.is_fast_blocks

0 commit comments

Comments
 (0)