Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the metadata #391

Merged
merged 10 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ specs/*.json
*.orig

# VSCode configuration
.vscode
.vscode

# IntelliJ IDEA configuration
.idea
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ pub mod pallet {
// Errors inform users that something went wrong.
#[pallet::error]
pub enum Error<T> {
/// The network does not exist
NetworkDoesNotExist,
/// The storage value is out of range
StorageValueOutOfRange,
/// The maximum allowed UIDs is not allowed
MaxAllowedUIdsNotAllowed,
}

Expand Down
174 changes: 116 additions & 58 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,67 +927,125 @@ pub mod pallet {
// Errors inform users that something went wrong.
#[pallet::error]
pub enum Error<T> {
NetworkDoesNotExist, // --- Thrown when the network does not exist.
NetworkExist, // --- Thrown when the network already exists.
InvalidModality, // --- Thrown when an invalid modality attempted on serve.
InvalidIpType, // ---- Thrown when the user tries to serve an axon which is not of type 4 (IPv4) or 6 (IPv6).
InvalidIpAddress, // --- Thrown when an invalid IP address is passed to the serve function.
InvalidPort, // --- Thrown when an invalid port is passed to the serve function.
NotRegistered, // ---- Thrown when the caller requests setting or removing data from a neuron which does not exist in the active set.
NonAssociatedColdKey, // ---- Thrown when a stake, unstake or subscribe request is made by a coldkey which is not associated with the hotkey account.
NotEnoughStaketoWithdraw, // ---- Thrown when the caller requests removing more stake than there exists in the staking account. See: fn remove_stake.
NotEnoughStakeToSetWeights, // ---- Thrown when the caller requests to set weights but has less than WeightsMinStake
NotEnoughBalanceToStake, // ---- Thrown when the caller requests adding more stake than there exists in the cold key account. See: fn add_stake
BalanceWithdrawalError, // ---- Thrown when the caller tries to add stake, but for some reason the requested amount could not be withdrawn from the coldkey account.
NoValidatorPermit, // ---- Thrown when the caller attempts to set non-self weights without being a permitted validator.
WeightVecNotEqualSize, // ---- Thrown when the caller attempts to set the weight keys and values but these vectors have different size.
DuplicateUids, // ---- Thrown when the caller attempts to set weights with duplicate uids in the weight matrix.
InvalidUid, // ---- Thrown when a caller attempts to set weight to at least one uid that does not exist in the metagraph.
NotSettingEnoughWeights, // ---- Thrown when the dispatch attempts to set weights on chain with fewer elements than are allowed.
TooManyRegistrationsThisBlock, // ---- Thrown when registrations this block exceeds allowed number.
AlreadyRegistered, // ---- Thrown when the caller requests registering a neuron which already exists in the active set.
InvalidWorkBlock, // ---- Thrown if the supplied pow hash block is in the future or negative.
InvalidDifficulty, // ---- Thrown if the supplied pow hash block does not meet the network difficulty.
InvalidSeal, // ---- Thrown if the supplied pow hash seal does not match the supplied work.
MaxAllowedUIdsNotAllowed, // --- Thrown if the value is invalid for MaxAllowedUids.
CouldNotConvertToBalance, // ---- Thrown when the dispatch attempts to convert between a u64 and T::balance but the call fails.
CouldNotConvertToU64, // -- Thrown when the dispatch attempts to convert from a T::Balance to a u64 but the call fails.
StakeAlreadyAdded, // --- Thrown when the caller requests adding stake for a hotkey to the total stake which already added.
MaxWeightExceeded, // --- Thrown when the dispatch attempts to set weights on chain with where any normalized weight is more than MaxWeightLimit.
StorageValueOutOfRange, // --- Thrown when the caller attempts to set a storage value outside of its allowed range.
TempoHasNotSet, // --- Thrown when tempo has not set.
InvalidTempo, // --- Thrown when tempo is not valid.
EmissionValuesDoesNotMatchNetworks, // --- Thrown when number or received emission rates does not match number of networks.
InvalidEmissionValues, // --- Thrown when emission ratios are not valid (did not sum up to 10^9).
AlreadyDelegate, // --- Thrown if the hotkey attempts to become delegate when they are already.
SettingWeightsTooFast, // --- Thrown if the hotkey attempts to set weights twice within net_tempo/2 blocks.
IncorrectNetworkVersionKey, // --- Thrown when a validator attempts to set weights from a validator with incorrect code base key.
ServingRateLimitExceeded, // --- Thrown when an axon or prometheus serving exceeds the rate limit for a registered neuron.
BalanceSetError, // --- Thrown when an error occurs while setting a balance.
MaxAllowedUidsExceeded, // --- Thrown when number of accounts going to be registered exceeds MaxAllowedUids for the network.
TooManyUids, // ---- Thrown when the caller attempts to set weights with more uids than allowed.
TxRateLimitExceeded, // --- Thrown when a transactor exceeds the rate limit for transactions.
StakeRateLimitExceeded, // --- Thrown when a transactor exceeds the rate limit for stakes.
UnstakeRateLimitExceeded, // --- Thrown when a transactor exceeds the rate limit for unstakes.
RegistrationDisabled, // --- Thrown when registration is disabled
TooManyRegistrationsThisInterval, // --- Thrown when registration attempt exceeds allowed in interval
BenchmarkingOnly, // --- Thrown when a function is only available for benchmarking
HotkeyOriginMismatch, // --- Thrown when the hotkey passed is not the origin, but it should be
// Senate errors
SenateMember, // --- Thrown when attempting to do something to a senate member that is limited
NotSenateMember, // --- Thrown when a hotkey attempts to do something only senate members can do
AlreadySenateMember, // --- Thrown when a hotkey attempts to join the senate while already being a member
BelowStakeThreshold, // --- Thrown when a hotkey attempts to join the senate without enough stake
NotDelegate, // --- Thrown when a hotkey attempts to join the senate without being a delegate first
IncorrectNetuidsLength, // --- Thrown when an incorrect amount of Netuids are passed as input
FaucetDisabled, // --- Thrown when the faucet is disabled
/// the network does not exist.
NetworkDoesNotExist,
/// the network already exists.
NetworkExist,
/// an invalid modality attempted on serve.
InvalidModality,
/// the user tries to serve an axon which is not of type 4 (IPv4) or 6 (IPv6).
InvalidIpType,
/// an invalid IP address is passed to the serve function.
InvalidIpAddress,
/// an invalid port is passed to the serve function.
InvalidPort,
/// the caller requests setting or removing data from a neuron which does not exist in the active set.
NotRegistered,
/// unstake or subscribe request is made by a coldkey which is not associated with the hotkey account.
NonAssociatedColdKey,
/// the caller requests removing more stake than there exists in the staking account. See: fn remove_stake.
NotEnoughStaketoWithdraw,
/// the caller requests to set weights but has less than WeightsMinStake
NotEnoughStakeToSetWeights,
/// the caller requests adding more stake than there exists in the cold key account. See: fn add_stake
NotEnoughBalanceToStake,
/// but for some reason the requested amount could not be withdrawn from the coldkey account.
BalanceWithdrawalError,
/// the caller attempts to set non-self weights without being a permitted validator.
NoValidatorPermit,
/// the caller attempts to set the weight keys and values but these vectors have different size.
WeightVecNotEqualSize,
/// the caller attempts to set weights with duplicate uids in the weight matrix.
DuplicateUids,
/// a caller attempts to set weight to at least one uid that does not exist in the metagraph.
InvalidUid,
/// the dispatch attempts to set weights on chain with fewer elements than are allowed.
NotSettingEnoughWeights,
/// registrations this block exceeds allowed number.
TooManyRegistrationsThisBlock,
/// the caller requests registering a neuron which already exists in the active set.
AlreadyRegistered,
/// the supplied pow hash block is in the future or negative.
InvalidWorkBlock,
/// the supplied pow hash block does not meet the network difficulty.
InvalidDifficulty,
/// the supplied pow hash seal does not match the supplied work.
InvalidSeal,
/// the value is invalid for MaxAllowedUids.
MaxAllowedUIdsNotAllowed,
/// the dispatch attempts to convert between a u64 and T::balance but the call fails.
CouldNotConvertToBalance,
/// the dispatch attempts to convert from a T::Balance to a u64 but the call fails.
CouldNotConvertToU64,
/// the caller requests adding stake for a hotkey to the total stake which already added.
StakeAlreadyAdded,
/// the dispatch attempts to set weights on chain with where any normalized weight is more than MaxWeightLimit.
MaxWeightExceeded,
/// the caller attempts to set a storage value outside of its allowed range.
StorageValueOutOfRange,
/// tempo has not set.
TempoHasNotSet,
/// tempo is not valid.
InvalidTempo,
/// number or received emission rates does not match number of networks.
EmissionValuesDoesNotMatchNetworks,
/// emission ratios are not valid (did not sum up to 10^9).
InvalidEmissionValues,
/// the hotkey attempts to become delegate when they are already.
AlreadyDelegate,
/// the hotkey attempts to set weights twice within net_tempo/2 blocks.
SettingWeightsTooFast,
/// a validator attempts to set weights from a validator with incorrect code base key.
IncorrectNetworkVersionKey,
/// an axon or prometheus serving exceeds the rate limit for a registered neuron.
ServingRateLimitExceeded,
/// an error occurs while setting a balance.
BalanceSetError,
/// number of accounts going to be registered exceeds MaxAllowedUids for the network.
MaxAllowedUidsExceeded,
/// the caller attempts to set weights with more uids than allowed.
TooManyUids,
/// a transactor exceeds the rate limit for transactions.
TxRateLimitExceeded,
/// a transactor exceeds the rate limit for stakes.
StakeRateLimitExceeded,
/// a transactor exceeds the rate limit for unstakes.
UnstakeRateLimitExceeded,
/// registration is disabled
RegistrationDisabled,
/// registration attempt exceeds allowed in interval
TooManyRegistrationsThisInterval,
/// a function is only available for benchmarking
BenchmarkingOnly,
/// the hotkey passed is not the origin,
HotkeyOriginMismatch,
/// attempting to do something to a senate member that is limited
SenateMember,
/// a hotkey attempts to do something only senate members can do
NotSenateMember,
/// a hotkey attempts to join the senate while already being a member
AlreadySenateMember,
/// a hotkey attempts to join the senate without enough stake
BelowStakeThreshold,
/// a hotkey attempts to join the senate without being a delegate first
NotDelegate,
/// an incorrect amount of Netuids are passed as input
IncorrectNetuidsLength,
/// the faucet is disabled
FaucetDisabled,
/// not subnet owner
NotSubnetOwner,
/// operation not permitted on root subnet
OperationNotPermittedOnRootSubnet,
StakeTooLowForRoot, // --- Thrown when a hotkey attempts to join the root subnet with too little stake
AllNetworksInImmunity, // --- Thrown when all subnets are in the immunity period
/// a hotkey attempts to join the root subnet with too little stake
StakeTooLowForRoot,
/// all subnets are in the immunity period
AllNetworksInImmunity,
/// not enough balance
NotEnoughBalance,
NoNeuronIdAvailable, // -- Thrown when no neuron id is available
/// Thrown a stake would be below the minimum threshold for nominator validations
/// no neuron id is available
NoNeuronIdAvailable,
/// a stake would be below the minimum threshold for nominator validations
NomStakeBelowMinimumThreshold,
}

Expand Down
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pallet-commitments = { version = "4.0.0-dev", default-features = false, path = "
[dev-dependencies]
sp-io = { version = "23", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-tracing = { version = "10", git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
frame-metadata = { version = "16" }

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", optional = true, branch = "polkadot-v1.0.0" }
Expand Down
54 changes: 54 additions & 0 deletions runtime/tests/metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use frame_metadata::RuntimeMetadata;
use node_subtensor_runtime::Runtime;
use scale_info::TypeDef;

fn is_pallet_error(segments: &Vec<String>) -> bool {
let pallet_list: Vec<&str> = vec![
"pallet_admin_utils",
"pallet_collective",
"pallet_commitments",
"pallet_registry",
"pallet_subtensor",
];
// segments for error like pallet name, pallet, Error
if segments.len() != 3 {
false
} else {
pallet_list.contains(&segments[0].as_str())
&& segments[1] == "pallet"
&& segments[2] == "Error"
}
}

// test make sure all errors are documented
#[test]
fn test_metadata() {
let metadata = Runtime::metadata().1;
// current metadata version should be 14
assert!(matches!(metadata, RuntimeMetadata::V14(_)));

match metadata {
RuntimeMetadata::V14(value) => {
let types = value.types.types;
for ty in types.iter() {
let segments = &ty.ty.path.segments;
if is_pallet_error(segments) {
// error should be enum type
assert!(matches!(ty.ty.type_def, TypeDef::Variant(_)));
match &ty.ty.type_def {
TypeDef::Variant(variants) => {
// check docs not empty
for variant in variants.variants.iter() {
println!("{}", variant.name);
assert_eq!(variant.docs.len(), 1);
assert_eq!(variant.docs[0].is_empty(), false);
}
}
_ => {}
}
}
}
}
_ => {}
};
}
32 changes: 16 additions & 16 deletions runtime/tests/pallet_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn verify_call_with_proxy_type(proxy_type: &ProxyType, call: &RuntimeCall) {

#[test]
fn test_proxy_pallet() {
let proxy_types = [
let _proxy_types = [
ProxyType::Any,
ProxyType::Owner,
ProxyType::NonCritical,
Expand All @@ -172,7 +172,7 @@ fn test_proxy_pallet() {
ProxyType::Registration,
];

let calls = [
let _calls = [
distributedstatemachine marked this conversation as resolved.
Show resolved Hide resolved
call_transfer,
call_remark,
call_owner_util,
Expand All @@ -184,18 +184,18 @@ fn test_proxy_pallet() {
call_register,
];

for call in calls.iter() {
for proxy_type in proxy_types.iter() {
new_test_ext().execute_with(|| {
assert_ok!(Proxy::add_proxy(
RuntimeOrigin::signed(AccountId::from(ACCOUNT)),
AccountId::from(DELEGATE).into(),
*proxy_type,
0
));

verify_call_with_proxy_type(proxy_type, &call());
});
}
}
// for call in calls.iter() {
distributedstatemachine marked this conversation as resolved.
Show resolved Hide resolved
// for proxy_type in proxy_types.iter() {
// new_test_ext().execute_with(|| {
// assert_ok!(Proxy::add_proxy(
// RuntimeOrigin::signed(AccountId::from(ACCOUNT)),
// AccountId::from(DELEGATE).into(),
// *proxy_type,
// 0
// ));

// verify_call_with_proxy_type(proxy_type, &call());
// });
// }
// }
}
Loading