bittensor
bittensor copied to clipboard
Translate Subtensor signed extension error codes in BTCLI & BTSDK
Task
As part of the BTCLI redesign, we would like to improve the user experience by providing relevant and meaningful error messages to the user. We should translate error codes from signed extensions from Subtensor into a meaningful message that is relevant for the user request.
Error code mappings
These error code mappings were provided by Nucleus team:
Custom Error Variants in Subtensor Signed Extension
This document describes the custom error variants used in the subtensor signed extension. The errors are presented to the user in the following format:
{'code': 1010, 'message': 'Invalid Transaction', 'data': 'Custom error: [Error Code]'}.
Custom error: 1
Description: The account (who) attempting the commit_weights call does not meet the minimum stake requirement for weights.
- Error from Subtensor:
{'code': 1010, 'message': 'Invalid Transaction', 'data': 'Custom error: 1'}
Custom error: 2
Description: The account (who) attempting the reveal_weights call does not meet the minimum stake requirement for weights.
- Error from Subtensor:
{'code': 1010, 'message': 'Invalid Transaction', 'data': 'Custom error: 2'}
Custom error: 3
Description: The account (who) attempting the set_weights call does not meet the minimum stake requirement for weights.
- Error from Subtensor:
{'code': 1010, 'message': 'Invalid Transaction', 'data': 'Custom error: 3'}
Custom error: 4
Description: The hotkey account passed to the set_root_weights call does not meet the minimum stake requirement for weights.
- Error from Subtensor:
{'code': 1010, 'message': 'Invalid Transaction', 'data': 'Custom error: 4'}
Custom error: 5
Description: The number of registrations for the current interval exceeds the maximum allowed for the given netuid. This applies to the register and burned_register calls.
- Error from Subtensor:
{'code': 1010, 'message': 'Invalid Transaction', 'data': 'Custom error: 5'}
6 & 7 no longer needed
These were related to the hack and coldkey arbitration which is no longer required.
Custom error: 6
Description: An account (who) under arbitration is attempting to call dissolve_network.
- Error from Subtensor:
{'code': 1010, 'message': 'Invalid Transaction', 'data': 'Custom error: 6'}
Custom error: 7
Description: The account (who) is attempting a balance transfer (either transfer_allow_death, transfer_keep_alive, or transfer_all) while under arbitration.
- Error from Subtensor:
{'code': 1010, 'message': 'Invalid Transaction', 'data': 'Custom error: 7'}
Background
The Subtensor signed extension contains the logic for handling incoming extrinsics before the enter the pool. When we handle these in the signed extension, substrate requires that we return a TransactionValidity which is defined as
pub type TransactionValidity = Result<ValidTransaction, TransactionValidityError>
Since the TransactionValidityError type is implemented by substrate Nucleus team are not able to implement any additional variants this way. This is the original reasoning behind returning the generic errors, like Nucleus do now, from the signed extension.
There exists a custom variant of the TransactionValidityError which takes a u8 which we can use to provide error codes to BTCLI / BTSDK.
The signed extension basically filters incoming extrinsics before they enter the transaction pool. After the extrinsics enter the pool they are executed. If the extrinsic fails during execution it will return an error from our errors.rs. If it is filtered before entering the pool it will return TransactionValidityError with an error code.
Subtensor related changes
Custom Errors for Signed Extensions (PR #700) Technical Change: Added labels to signed extension errors. Impact: Improved error handling and debugging capabilities. Action Required: CLI team needs to implement decoding for these new error labels. User-Facing: Yes URL: https://github.com/opentensor/subtensor/pull/700
Related Discord discussions
https://discord.com/channels/799672011265015819/1263701469110992989 https://discord.com/channels/799672011265015819/1267904639748280381