Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1814,23 +1814,36 @@ def set_weights(

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】.
"""
retries = 0
success = False
uid = self.get_uid_for_hotkey_on_subnet(wallet.hotkey.ss58_address, netuid)

if self.commit_reveal_enabled(netuid=netuid) is True:
# go with `commit reveal v3` extrinsic
return commit_reveal_v3_extrinsic(
subtensor=self,
wallet=wallet,
netuid=netuid,
uids=uids,
weights=weights,
version_key=version_key,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
)
message = "No attempt made. Perhaps it is too soon to commit weights!"
while (
self.blocks_since_last_update(netuid, uid) # type: ignore
> self.weights_rate_limit(netuid) # type: ignore
and retries < max_retries
and success is False
):
logging.info(
f"Committing weights for subnet #{netuid}. Attempt {retries + 1} of {max_retries}."
)
success, message = commit_reveal_v3_extrinsic(
subtensor=self,
wallet=wallet,
netuid=netuid,
uids=uids,
weights=weights,
version_key=version_key,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
)
retries += 1
return success, message
else:
# go with classic `set weights` logic
uid = self.get_uid_for_hotkey_on_subnet(wallet.hotkey.ss58_address, netuid)
retries = 0
success = False
message = "No attempt made. Perhaps it is too soon to set weights!"
while (
self.blocks_since_last_update(netuid, uid) # type: ignore
Expand Down
6 changes: 6 additions & 0 deletions tests/unit_tests/test_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2850,6 +2850,12 @@ def test_set_weights_with_commit_reveal_enabled(subtensor, mocker):
mocked_commit_reveal_v3_extrinsic = mocker.patch.object(
subtensor_module, "commit_reveal_v3_extrinsic"
)
mocked_commit_reveal_v3_extrinsic.return_value = (
True,
"Weights committed successfully",
)
mocker.patch.object(subtensor, "blocks_since_last_update", return_value=181)
mocker.patch.object(subtensor, "weights_rate_limit", return_value=180)

# Call
result = subtensor.set_weights(
Expand Down