Skip to content

Commit

Permalink
Merge branch 'staging' into update/bt-decode-0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheem-opentensor authored Dec 6, 2024
2 parents 266296f + 6969722 commit 92bb901
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 124 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 8.4.3 /2024-12-02

## What's Changed

* Fix logging config parsing by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2500
* Improve `submit_extrinsic` util by @thewhaleking in https://github.com/opentensor/bittensor/pull/2502
* Backmerge master to staging for 843 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2505
* WS ensure_connected socket catch by @thewhaleking in https://github.com/opentensor/bittensor/pull/2507

**Full Changelog**: https://github.com/opentensor/bittensor/compare/v8.4.2...v8.4.3

## 8.4.2 /2024-11-28

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.4.2
8.4.3
8 changes: 3 additions & 5 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,11 +1184,9 @@ async def sign_and_send_extrinsic(
if await response.is_success:
return True, ""
else:
return False, format_error_message(
await response.error_message, substrate=self.substrate
)
return False, format_error_message(await response.error_message)
except SubstrateRequestException as e:
return False, format_error_message(e, substrate=self.substrate)
return False, format_error_message(e)

async def get_children(self, hotkey: str, netuid: int) -> tuple[bool, list, str]:
"""
Expand Down Expand Up @@ -1218,7 +1216,7 @@ async def get_children(self, hotkey: str, netuid: int) -> tuple[bool, list, str]
else:
return True, [], ""
except SubstrateRequestException as e:
return False, [], format_error_message(e, self.substrate)
return False, [], format_error_message(e)

async def get_subnet_hyperparameters(
self, netuid: int, block_hash: Optional[str] = None, reuse_block: bool = False
Expand Down
4 changes: 1 addition & 3 deletions bittensor/core/extrinsics/async_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ async def _do_pow_register(
# process if registration successful, try again if pow is still valid
await response.process_events()
if not await response.is_success:
return False, format_error_message(
error_message=await response.error_message, substrate=subtensor.substrate
)
return False, format_error_message(error_message=await response.error_message)
# Successful registration
else:
return True, None
Expand Down
6 changes: 2 additions & 4 deletions bittensor/core/extrinsics/async_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ async def _do_set_root_weights(
if await response.is_success:
return True, "Successfully set weights."
else:
return False, format_error_message(
await response.error_message, substrate=subtensor.substrate
)
return False, format_error_message(await response.error_message)


async def set_root_weights_extrinsic(
Expand Down Expand Up @@ -263,6 +261,6 @@ async def set_root_weights_extrinsic(
return False

except SubstrateRequestException as e:
fmt_err = format_error_message(e, subtensor.substrate)
fmt_err = format_error_message(e)
logging.error(f":cross_mark: [red]Failed error:[/red] {fmt_err}")
return False
4 changes: 1 addition & 3 deletions bittensor/core/extrinsics/async_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ async def _do_transfer(
return (
False,
"",
format_error_message(
await response.error_message, substrate=subtensor.substrate
),
format_error_message(await response.error_message),
)


Expand Down
8 changes: 2 additions & 6 deletions bittensor/core/extrinsics/async_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ async def _do_set_weights(
if await response.is_success:
return True, "Successfully set weights."
else:
return False, format_error_message(
response.error_message, substrate=subtensor.substrate
)
return False, format_error_message(response.error_message)


async def set_weights_extrinsic(
Expand Down Expand Up @@ -206,9 +204,7 @@ async def _do_commit_weights(
if await response.is_success:
return True, None
else:
return False, format_error_message(
response.error_message, substrate=subtensor.substrate
)
return False, format_error_message(response.error_message)


async def commit_weights_extrinsic(
Expand Down
8 changes: 2 additions & 6 deletions bittensor/core/extrinsics/commit_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ def commit_weights_extrinsic(
logging.info(success_message)
return True, success_message
else:
error_message = format_error_message(
error_message, substrate=subtensor.substrate
)
error_message = format_error_message(error_message)
logging.error(f"Failed to commit weights: {error_message}")
return False, error_message

Expand Down Expand Up @@ -249,8 +247,6 @@ def reveal_weights_extrinsic(
logging.info(success_message)
return True, success_message
else:
error_message = format_error_message(
error_message, substrate=subtensor.substrate
)
error_message = format_error_message(error_message)
logging.error(f"Failed to reveal weights: {error_message}")
return False, error_message
8 changes: 2 additions & 6 deletions bittensor/core/extrinsics/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def _do_pow_register(
# process if registration successful, try again if pow is still valid
response.process_events()
if not response.is_success:
return False, format_error_message(
response.error_message, substrate=self.substrate
)
return False, format_error_message(response.error_message)
# Successful registration
else:
return True, None
Expand Down Expand Up @@ -310,9 +308,7 @@ def _do_burned_register(
# process if registration successful, try again if pow is still valid
response.process_events()
if not response.is_success:
return False, format_error_message(
response.error_message, substrate=self.substrate
)
return False, format_error_message(response.error_message)
# Successful registration
else:
return True, None
Expand Down
4 changes: 1 addition & 3 deletions bittensor/core/extrinsics/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def _do_root_register(
# process if registration successful, try again if pow is still valid
response.process_events()
if not response.is_success:
return False, format_error_message(
response.error_message, substrate=self.substrate
)
return False, format_error_message(response.error_message)
# Successful registration
else:
return True, None
Expand Down
8 changes: 2 additions & 6 deletions bittensor/core/extrinsics/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ def serve_extrinsic(
)
return True
else:
logging.error(
f"Failed: {format_error_message(error_message, substrate=subtensor.substrate)}"
)
logging.error(f"Failed: {format_error_message(error_message)}")
return False
else:
return True
Expand Down Expand Up @@ -301,9 +299,7 @@ def publish_metadata(
if response.is_success:
return True
else:
raise MetadataError(
format_error_message(response.error_message, substrate=self.substrate)
)
raise MetadataError(format_error_message(response.error_message))


# Community uses this function directly
Expand Down
4 changes: 1 addition & 3 deletions bittensor/core/extrinsics/set_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def do_set_weights(
if response.is_success:
return True, "Successfully set weights."
else:
return False, format_error_message(
response.error_message, substrate=self.substrate
)
return False, format_error_message(response.error_message)


# Community uses this extrinsic directly and via `subtensor.set_weights`
Expand Down
4 changes: 1 addition & 3 deletions bittensor/core/extrinsics/staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def _do_stake(
if response.is_success:
return True
else:
raise StakeError(
format_error_message(response.error_message, substrate=self.substrate)
)
raise StakeError(format_error_message(response.error_message))


def _check_threshold_amount(
Expand Down
2 changes: 1 addition & 1 deletion bittensor/core/extrinsics/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def transfer_extrinsic(
)
else:
logging.error(
f":cross_mark: [red]Failed[/red]: {format_error_message(error_message, substrate=subtensor.substrate)}"
f":cross_mark: [red]Failed[/red]: {format_error_message(error_message)}"
)

if success:
Expand Down
4 changes: 1 addition & 3 deletions bittensor/core/extrinsics/unstaking.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def _do_unstake(
if response.is_success:
return True
else:
raise StakeError(
format_error_message(response.error_message, substrate=self.substrate)
)
raise StakeError(format_error_message(response.error_message))


def _check_threshold_amount(subtensor: "Subtensor", stake_balance: "Balance") -> bool:
Expand Down
4 changes: 1 addition & 3 deletions bittensor/core/extrinsics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ def submit():
wait_for_finalization=wait_for_finalization,
)
except SubstrateRequestException as e:
logging.error(
format_error_message(e.args[0], substrate=subtensor.substrate)
)
logging.error(format_error_message(e.args[0]))
# Re-raise the exception for retrying of the extrinsic call. If we remove the retry logic,
# the raise will need to be removed.
raise
Expand Down
2 changes: 1 addition & 1 deletion bittensor/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

__version__ = "8.4.2"
__version__ = "8.4.3"

import os
import re
Expand Down
24 changes: 3 additions & 21 deletions bittensor/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,13 @@ def get_hash(content, encoding="utf-8"):
return sha3.hexdigest()


def format_error_message(
error_message: Union[dict, Exception],
substrate: Union["AsyncSubstrateInterface", "SubstrateInterface"],
) -> str:
def format_error_message(error_message: Union[dict, Exception]) -> str:
"""
Formats an error message from the Subtensor error information for use in extrinsics.
Args:
error_message: A dictionary containing the error information from Subtensor, or a SubstrateRequestException
containing dictionary literal args.
substrate: The initialised SubstrateInterface object to use.
Returns:
str: A formatted error message string.
Expand Down Expand Up @@ -204,22 +200,8 @@ def format_error_message(
err_data = error_message.get("data", "")

# subtensor custom error marker
if err_data.startswith("Custom error:") and substrate:
if substrate.metadata:
try:
pallet = substrate.metadata.get_metadata_pallet(
"SubtensorModule"
)
error_index = int(err_data.split("Custom error:")[-1])

error_dict = pallet.errors[error_index].value
err_type = error_dict.get("message", err_type)
err_docs = error_dict.get("docs", [])
err_description = err_docs[0] if err_docs else err_description
except (AttributeError, IndexError):
logging.error(
"[red]Substrate pallets data unavailable. This is usually caused by an uninitialized substrate.[/red]"
)
if err_data.startswith("Custom error:"):
err_description = f"{err_data} | Please consult https://docs.bittensor.com/subtensor-nodes/subtensor-error-messages"
else:
err_description = err_data

Expand Down
Loading

0 comments on commit 92bb901

Please sign in to comment.