diff --git a/src/contract.rs b/src/contract.rs index 3aa126a..53e53e0 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -24,14 +24,14 @@ use crate::state::{ BURN_REGISTRATIONS_THIS_INTERVAL, CONSENSUS, DEFAULT_TAKE, DELEGATES, DENOM, DIFFICULTY, DIVIDENDS, EMISSION, EMISSION_VALUES, IMMUNITY_PERIOD, INCENTIVE, KAPPA, LAST_ADJUSTMENT_BLOCK, LAST_UPDATE, MAX_ALLOWED_UIDS, MAX_ALLOWED_VALIDATORS, MAX_BURN, MAX_DIFFICULTY, - MAX_REGISTRATION_PER_BLOCK, MAX_WEIGHTS_LIMIT, MIN_ALLOWED_WEIGHTS, MIN_BURN, MIN_DIFFICULTY, - NETWORKS_ADDED, NETWORK_IMMUNITY_PERIOD, NETWORK_LAST_LOCK_COST, NETWORK_LAST_REGISTERED, - NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_LOCK_COST, NETWORK_MODALITY, NETWORK_RATE_LIMIT, - NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED, OWNER, PENDING_EMISSION, - POW_REGISTRATIONS_THIS_INTERVAL, PROMETHEUS, PRUNING_SCORES, RANK, + MAX_REGISTRATION_PER_BLOCK, MAX_WEIGHTS_LIMIT, METADATA, MIN_ALLOWED_WEIGHTS, MIN_BURN, + MIN_DIFFICULTY, NETWORKS_ADDED, NETWORK_IMMUNITY_PERIOD, NETWORK_LAST_LOCK_COST, + NETWORK_LAST_REGISTERED, NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_LOCK_COST, + NETWORK_MODALITY, NETWORK_RATE_LIMIT, NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED, + OWNER, PENDING_EMISSION, POW_REGISTRATIONS_THIS_INTERVAL, PROMETHEUS, PRUNING_SCORES, RANK, RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, REGISTRATIONS_THIS_INTERVAL, RHO, - ROOT, SCALING_LAW_POWER, SERVING_RATE_LIMIT, STAKE, SUBNETWORK_N, SUBNET_LIMIT, SUBNET_LOCKED, - SUBNET_OWNER, SUBNET_OWNER_CUT, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_COLDKEY_STAKE, + ROOT, SERVING_RATE_LIMIT, STAKE, SUBNETWORK_N, SUBNET_LIMIT, SUBNET_LOCKED, SUBNET_OWNER, + SUBNET_OWNER_CUT, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_COLDKEY_STAKE, TOTAL_HOTKEY_STAKE, TOTAL_ISSUANCE, TOTAL_NETWORKS, TOTAL_STAKE, TRUST, TX_RATE_LIMIT, UIDS, VALIDATOR_PERMIT, VALIDATOR_TRUST, WEIGHTS_SET_RATE_LIMIT, WEIGHTS_VERSION_KEY, }; @@ -48,8 +48,8 @@ use crate::utils::{ do_sudo_set_min_allowed_weights, do_sudo_set_min_burn, do_sudo_set_min_difficulty, do_sudo_set_network_immunity_period, do_sudo_set_network_min_lock_cost, do_sudo_set_network_rate_limit, do_sudo_set_network_registration_allowed, - do_sudo_set_rao_recycled, do_sudo_set_rho, do_sudo_set_scaling_law_power, - do_sudo_set_serving_rate_limit, do_sudo_set_subnet_limit, do_sudo_set_subnet_owner_cut, + do_sudo_set_rao_recycled, do_sudo_set_rho, do_sudo_set_serving_rate_limit, + do_sudo_set_subnet_limit, do_sudo_set_subnet_metadata, do_sudo_set_subnet_owner_cut, do_sudo_set_target_registrations_per_interval, do_sudo_set_tempo, do_sudo_set_total_issuance, do_sudo_set_tx_rate_limit, do_sudo_set_validator_permit_for_uid, do_sudo_set_validator_prune_len, do_sudo_set_weights_set_rate_limit, @@ -78,8 +78,6 @@ pub fn instantiate( DENOM.save(deps.storage, &"boot".to_string())?; } - // TODO remove from InstantiateMsg - // // Set initial total issuance from balances TOTAL_ISSUANCE.save(deps.storage, &0)?; TOTAL_STAKE.save(deps.storage, &0)?; @@ -96,20 +94,17 @@ pub fn instantiate( DEFAULT_TAKE.save(deps.storage, &4096)?; TX_RATE_LIMIT.save(deps.storage, &0)?; - NETWORK_LAST_LOCK_COST.save(deps.storage, &100_000_000_000)?; - NETWORK_MIN_LOCK_COST.save(deps.storage, &100_000_000_000)?; - NETWORK_LOCK_REDUCTION_INTERVAL.save(deps.storage, &(7 * 7200))?; // test value, change to 14 * 7200; + NETWORK_LAST_LOCK_COST.save(deps.storage, &10_000_000_000)?; + NETWORK_MIN_LOCK_COST.save(deps.storage, &10_000_000_000)?; + NETWORK_LOCK_REDUCTION_INTERVAL.save(deps.storage, &(7 * 7200))?; // -- Root network initialization -- - - // Get the root network uid. let root_netuid: u16 = 0; SUBNET_OWNER.save(deps.storage, root_netuid, &info.sender)?; - // TODO revisit set of 1 SUBNETWORK_N.save(deps.storage, root_netuid, &0)?; NETWORKS_ADDED.save(deps.storage, root_netuid, &true)?; - NETWORK_MODALITY.save(deps.storage, root_netuid, &u16::MAX)?; + NETWORK_MODALITY.save(deps.storage, root_netuid, &u16::MAX)?; // revisit MAX_ALLOWED_UIDS.save(deps.storage, root_netuid, &64)?; MAX_ALLOWED_VALIDATORS.save(deps.storage, root_netuid, &64)?; MIN_ALLOWED_WEIGHTS.save(deps.storage, root_netuid, &1)?; @@ -118,7 +113,6 @@ pub fn instantiate( NETWORK_REGISTRATION_ALLOWED.save(deps.storage, root_netuid, &true)?; TARGET_REGISTRATIONS_PER_INTERVAL.save(deps.storage, root_netuid, &1)?; WEIGHTS_VERSION_KEY.save(deps.storage, root_netuid, &0)?; - SUBNET_OWNER.save(deps.storage, root_netuid, &info.sender)?; NETWORK_REGISTERED_AT.save(deps.storage, root_netuid, &env.block.height)?; WEIGHTS_SET_RATE_LIMIT.save(deps.storage, root_netuid, &100)?; @@ -148,20 +142,20 @@ pub fn instantiate( EMISSION_VALUES.save(deps.storage, root_netuid, &0)?; NETWORK_LAST_REGISTERED.save(deps.storage, &0)?; TOTAL_NETWORKS.save(deps.storage, &1)?; - SCALING_LAW_POWER.save(deps.storage, root_netuid, &50)?; + METADATA.save( + deps.storage, + root_netuid, + &"Qmd2anGbDQj7pYWMZwv9SEw11QFLQu3nzoGXfi1KwLy3Zr".to_string(), + )?; // -- Subnetwork 1 initialization -- - - // Subnet config values let netuid: u16 = 1; - let tempo = 10; - let max_uids = 4096; SUBNET_OWNER.save(deps.storage, netuid, &info.sender)?; NETWORKS_ADDED.save(deps.storage, netuid, &true)?; - TEMPO.save(deps.storage, netuid, &tempo)?; + TEMPO.save(deps.storage, netuid, &10)?; NETWORK_MODALITY.save(deps.storage, netuid, &0)?; - // TEMPO.save(deps.storage, netuid, &0)?; + TEMPO.save(deps.storage, netuid, &10)?; KAPPA.save(deps.storage, netuid, &0)?; DIFFICULTY.save(deps.storage, netuid, &10_000_000)?; IMMUNITY_PERIOD.save(deps.storage, netuid, &7200)?; @@ -173,7 +167,7 @@ pub fn instantiate( POW_REGISTRATIONS_THIS_INTERVAL.save(deps.storage, netuid, &0)?; BURN_REGISTRATIONS_THIS_INTERVAL.save(deps.storage, netuid, &0)?; MAX_ALLOWED_VALIDATORS.save(deps.storage, netuid, &64)?; - MAX_ALLOWED_UIDS.save(deps.storage, netuid, &max_uids)?; + MAX_ALLOWED_UIDS.save(deps.storage, netuid, &1024)?; WEIGHTS_VERSION_KEY.save(deps.storage, netuid, &0)?; WEIGHTS_SET_RATE_LIMIT.save(deps.storage, netuid, &100)?; @@ -199,8 +193,12 @@ pub fn instantiate( SUBNETWORK_N.save(deps.storage, netuid, &0)?; SUBNET_LOCKED.save(deps.storage, netuid, &0)?; TARGET_REGISTRATIONS_PER_INTERVAL.save(deps.storage, netuid, &1)?; - SCALING_LAW_POWER.save(deps.storage, netuid, &50)?; NETWORK_REGISTRATION_ALLOWED.save(deps.storage, netuid, &true)?; + METADATA.save( + deps.storage, + root_netuid, + &"Qmd2anGbDQj7pYWMZwv9SEw11QFLQu3nzoGXfi1KwLy3Zr".to_string(), + )?; RANK.save(deps.storage, netuid, &vec![])?; TRUST.save(deps.storage, netuid, &vec![])?; @@ -405,10 +403,6 @@ pub fn execute( netuid, validator_prune_len, } => do_sudo_set_validator_prune_len(deps, env, info, netuid, validator_prune_len), - ExecuteMsg::SudoSetScalingLawPower { - netuid, - scaling_law_power, - } => do_sudo_set_scaling_law_power(deps, env, info, netuid, scaling_law_power), ExecuteMsg::SudoSetImmunityPeriod { netuid, immunity_period, @@ -474,6 +468,9 @@ pub fn execute( ExecuteMsg::SudoSetBlockEmission { emission } => { do_sudo_set_block_emission(deps, env, info, emission) } + ExecuteMsg::SudoSetSubnetMetadata { netuid, particle } => { + do_sudo_set_subnet_metadata(deps, env, info, netuid, particle) + } } } diff --git a/src/error.rs b/src/error.rs index 4591b3a..ade961d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -160,4 +160,7 @@ pub enum ContractError { #[error("Thrown when all subnets are in the immunity period")] AllNetworksInImmunity {}, + + #[error("Thrown when particle metadata size is invalid")] + MetadataSizeError {}, } diff --git a/src/msg.rs b/src/msg.rs index a628fd6..be7a6f5 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -147,10 +147,6 @@ pub enum ExecuteMsg { netuid: u16, validator_prune_len: u64, }, - SudoSetScalingLawPower { - netuid: u16, - scaling_law_power: u16, - }, SudoSetImmunityPeriod { netuid: u16, immunity_period: u16, @@ -210,6 +206,10 @@ pub enum ExecuteMsg { SudoSetBlockEmission { emission: u64, }, + SudoSetSubnetMetadata { + netuid: u16, + particle: String, + }, } #[cw_serde] diff --git a/src/root.rs b/src/root.rs index 916d91a..2452260 100644 --- a/src/root.rs +++ b/src/root.rs @@ -15,13 +15,13 @@ use crate::state::{ BONDS_MOVING_AVERAGE, BURN, BURN_REGISTRATIONS_THIS_INTERVAL, CONSENSUS, DENOM, DIFFICULTY, DIVIDENDS, EMISSION, EMISSION_VALUES, IMMUNITY_PERIOD, INCENTIVE, KAPPA, KEYS, LAST_ADJUSTMENT_BLOCK, LAST_UPDATE, MAX_ALLOWED_UIDS, MAX_ALLOWED_VALIDATORS, MAX_BURN, - MAX_DIFFICULTY, MAX_REGISTRATION_PER_BLOCK, MAX_WEIGHTS_LIMIT, MIN_ALLOWED_WEIGHTS, MIN_BURN, - MIN_DIFFICULTY, NETWORKS_ADDED, NETWORK_IMMUNITY_PERIOD, NETWORK_LAST_LOCK_COST, + MAX_DIFFICULTY, MAX_REGISTRATION_PER_BLOCK, MAX_WEIGHTS_LIMIT, METADATA, MIN_ALLOWED_WEIGHTS, + MIN_BURN, MIN_DIFFICULTY, NETWORKS_ADDED, NETWORK_IMMUNITY_PERIOD, NETWORK_LAST_LOCK_COST, NETWORK_LAST_REGISTERED, NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_LOCK_COST, NETWORK_MODALITY, NETWORK_RATE_LIMIT, NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED, PENDING_EMISSION, POW_REGISTRATIONS_THIS_INTERVAL, PRUNING_SCORES, RANK, RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, REGISTRATIONS_THIS_INTERVAL, RHO, - SCALING_LAW_POWER, SERVING_RATE_LIMIT, SUBNETWORK_N, SUBNET_LIMIT, SUBNET_OWNER, + SERVING_RATE_LIMIT, SUBNETWORK_N, SUBNET_LIMIT, SUBNET_OWNER, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_NETWORKS, TRUST, UIDS, VALIDATOR_PERMIT, VALIDATOR_TRUST, WEIGHTS, WEIGHTS_SET_RATE_LIMIT, WEIGHTS_VERSION_KEY, }; @@ -821,7 +821,11 @@ pub fn init_new_network( SERVING_RATE_LIMIT.save(store, netuid, &50)?; ADJUSTMENTS_ALPHA.save(store, netuid, &0)?; LAST_UPDATE.save(store, netuid, &vec![])?; - SCALING_LAW_POWER.save(store, netuid, &50)?; + METADATA.save( + store, + netuid, + &"Qmd2anGbDQj7pYWMZwv9SEw11QFLQu3nzoGXfi1KwLy3Zr".to_string(), + )?; Ok(()) } @@ -923,9 +927,9 @@ pub fn remove_network(store: &mut dyn Storage, netuid: u16) -> Result<(), Contra MIN_DIFFICULTY.remove(store, netuid); MAX_DIFFICULTY.remove(store, netuid); ADJUSTMENTS_ALPHA.remove(store, netuid); - SCALING_LAW_POWER.remove(store, netuid); NETWORK_REGISTRATION_ALLOWED.remove(store, netuid); TARGET_REGISTRATIONS_PER_INTERVAL.remove(store, netuid); + METADATA.remove(store, netuid); Ok(()) } diff --git a/src/state.rs b/src/state.rs index 923bcd2..e0d966a 100644 --- a/src/state.rs +++ b/src/state.rs @@ -115,6 +115,8 @@ pub const LAST_MECHANISM_STEP_BLOCK: Map = Map::new("last_mechanism_st pub const SUBNET_OWNER: Map = Map::new("subnet_owner"); // --- MAP (netuid ) --> subnet_locked pub const SUBNET_LOCKED: Map = Map::new("subnet_locked"); +// --- MAP (netuid ) --> metadata +pub const METADATA: Map = Map::new("metadata"); // ================================= // ==== Axon / Promo Endpoints ===== @@ -198,8 +200,6 @@ pub const BONDS_MOVING_AVERAGE: Map = Map::new("bonds_moving_average") pub const WEIGHTS_SET_RATE_LIMIT: Map = Map::new("weights_set_rate_limit"); // --- MAP ( netuid ) --> validator_prune_len pub const VALIDATOR_PRUNE_LEN: Map = Map::new("validator_prune_len"); -// --- MAP ( netuid ) --> scaling_law_power -pub const SCALING_LAW_POWER: Map = Map::new("scaling_law_power"); // --- MAP ( netuid ) --> target_registrations_this_interval // TODO update to target_regs_per_interval, check later pub const TARGET_REGISTRATIONS_PER_INTERVAL: Map = Map::new("target_regs_per_interval"); diff --git a/src/state_info.rs b/src/state_info.rs index 4a4fcbb..aefd261 100644 --- a/src/state_info.rs +++ b/src/state_info.rs @@ -14,12 +14,11 @@ use crate::state::{ NETWORK_MODALITY, NETWORK_RATE_LIMIT, NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED, NEURONS_TO_PRUNE_AT_NEXT_EPOCH, OWNER, PENDING_EMISSION, POW_REGISTRATIONS_THIS_INTERVAL, PROMETHEUS, PRUNING_SCORES, RANK, RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, - REGISTRATIONS_THIS_INTERVAL, RHO, ROOT, SCALING_LAW_POWER, SERVING_RATE_LIMIT, STAKE, - SUBNETWORK_N, SUBNET_LIMIT, SUBNET_LOCKED, SUBNET_OWNER, SUBNET_OWNER_CUT, - TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_COLDKEY_STAKE, TOTAL_HOTKEY_STAKE, - TOTAL_ISSUANCE, TOTAL_NETWORKS, TOTAL_STAKE, TRUST, TX_RATE_LIMIT, UIDS, USED_WORK, - VALIDATOR_PERMIT, VALIDATOR_PRUNE_LEN, VALIDATOR_TRUST, WEIGHTS, WEIGHTS_SET_RATE_LIMIT, - WEIGHTS_VERSION_KEY, + REGISTRATIONS_THIS_INTERVAL, RHO, ROOT, SERVING_RATE_LIMIT, STAKE, SUBNETWORK_N, SUBNET_LIMIT, + SUBNET_LOCKED, SUBNET_OWNER, SUBNET_OWNER_CUT, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, + TOTAL_COLDKEY_STAKE, TOTAL_HOTKEY_STAKE, TOTAL_ISSUANCE, TOTAL_NETWORKS, TOTAL_STAKE, TRUST, + TX_RATE_LIMIT, UIDS, USED_WORK, VALIDATOR_PERMIT, VALIDATOR_PRUNE_LEN, VALIDATOR_TRUST, + WEIGHTS, WEIGHTS_SET_RATE_LIMIT, WEIGHTS_VERSION_KEY, }; #[cw_serde] @@ -90,7 +89,6 @@ pub struct StateInfo { bonds_moving_average: Vec<(u16, u64)>, weights_set_rate_limit: Vec<(u16, u64)>, validator_prune_len: Vec<(u16, u64)>, - scaling_law_power: Vec<(u16, u16)>, target_registrations_per_interval: Vec<(u16, u16)>, block_at_registration: Vec<((u16, u16), u64)>, adjustments_alpha: Vec<(u16, u64)>, @@ -329,10 +327,6 @@ pub fn get_state_info(store: &dyn Storage) -> StdResult { .range(store, None, None, Order::Ascending) .collect::>>() .unwrap(); - let scaling_law_power: Vec<(u16, u16)> = SCALING_LAW_POWER - .range(store, None, None, Order::Ascending) - .collect::>>() - .unwrap(); let target_registrations_per_interval: Vec<(u16, u16)> = TARGET_REGISTRATIONS_PER_INTERVAL .range(store, None, None, Order::Ascending) .collect::>>() @@ -477,7 +471,6 @@ pub fn get_state_info(store: &dyn Storage) -> StdResult { bonds_moving_average, weights_set_rate_limit, validator_prune_len, - scaling_law_power, target_registrations_per_interval, block_at_registration, adjustments_alpha, diff --git a/src/subnet_info.rs b/src/subnet_info.rs index 28e0b92..aa319a3 100644 --- a/src/subnet_info.rs +++ b/src/subnet_info.rs @@ -5,9 +5,9 @@ use crate::root::if_subnet_exist; use crate::state::{ ACTIVITY_CUTOFF, ADJUSTMENT_INTERVAL, BLOCKS_SINCE_LAST_STEP, BONDS_MOVING_AVERAGE, BURN, DIFFICULTY, EMISSION_VALUES, IMMUNITY_PERIOD, KAPPA, MAX_ALLOWED_UIDS, MAX_ALLOWED_VALIDATORS, - MAX_BURN, MAX_DIFFICULTY, MAX_REGISTRATION_PER_BLOCK, MAX_WEIGHTS_LIMIT, MIN_ALLOWED_WEIGHTS, - MIN_BURN, MIN_DIFFICULTY, NETWORKS_ADDED, NETWORK_MODALITY, NETWORK_REGISTRATION_ALLOWED, RHO, - SCALING_LAW_POWER, SUBNET_OWNER, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, + MAX_BURN, MAX_DIFFICULTY, MAX_REGISTRATION_PER_BLOCK, MAX_WEIGHTS_LIMIT, METADATA, + MIN_ALLOWED_WEIGHTS, MIN_BURN, MIN_DIFFICULTY, NETWORKS_ADDED, NETWORK_MODALITY, + NETWORK_REGISTRATION_ALLOWED, RHO, SUBNET_OWNER, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, WEIGHTS_SET_RATE_LIMIT, WEIGHTS_VERSION_KEY, }; use crate::uids::get_subnetwork_n; @@ -22,16 +22,15 @@ pub struct SubnetInfo { pub max_allowed_validators: u16, pub min_allowed_weights: u16, pub max_weights_limit: u16, - pub scaling_law_power: u16, pub subnetwork_n: u16, pub max_allowed_uids: u16, pub blocks_since_last_step: u64, pub tempo: u16, pub network_modality: u16, - pub network_connect: Vec<[u16; 2]>, pub emission_values: u64, pub burn: u64, pub owner: Addr, + pub metadata: String, } #[cw_serde] @@ -68,7 +67,6 @@ pub fn get_subnet_info(deps: Deps, netuid: u16) -> StdResult> let max_allowed_validators = MAX_ALLOWED_VALIDATORS.load(deps.storage, netuid)?; let min_allowed_weights = MIN_ALLOWED_WEIGHTS.load(deps.storage, netuid)?; let max_weights_limit = MAX_WEIGHTS_LIMIT.load(deps.storage, netuid)?; - let scaling_law_power = SCALING_LAW_POWER.load(deps.storage, netuid)?; let subnetwork_n = get_subnetwork_n(deps.storage, netuid); let max_allowed_uids = MAX_ALLOWED_UIDS.load(deps.storage, netuid)?; let blocks_since_last_step = BLOCKS_SINCE_LAST_STEP.load(deps.storage, netuid)?; @@ -77,14 +75,7 @@ pub fn get_subnet_info(deps: Deps, netuid: u16) -> StdResult> let emission_values = EMISSION_VALUES.load(deps.storage, netuid)?; let burn = BURN.load(deps.storage, netuid)?; let owner = SUBNET_OWNER.load(deps.storage, netuid)?; - // TODO update - // let owner = SUBNET_OWNER.load(deps.storage, netuid).map_err(|_| return Ok(None))?; - - // DEPRECATED - let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new(); - // DEPRECATED for ( _netuid_, con_req) in < NetworkConnect as IterableStorageDoubleMap >::iter_prefix(netuid) { - // network_connect.push([_netuid_, con_req]); - // } + let metadata = METADATA.load(deps.storage, netuid)?; return Ok(Some(SubnetInfo { rho: rho.into(), @@ -95,16 +86,15 @@ pub fn get_subnet_info(deps: Deps, netuid: u16) -> StdResult> max_allowed_validators: max_allowed_validators.into(), min_allowed_weights: min_allowed_weights.into(), max_weights_limit: max_weights_limit.into(), - scaling_law_power: scaling_law_power.into(), subnetwork_n: subnetwork_n.into(), max_allowed_uids: max_allowed_uids.into(), blocks_since_last_step: blocks_since_last_step.into(), tempo: tempo.into(), network_modality: network_modality.into(), - network_connect, emission_values: emission_values.into(), burn, owner: owner.into(), + metadata: metadata.into(), })); } diff --git a/src/test_helpers.rs b/src/test_helpers.rs index 92baf4c..3bf9677 100644 --- a/src/test_helpers.rs +++ b/src/test_helpers.rs @@ -205,7 +205,7 @@ pub fn pow_register_ok_neuron( result } -pub fn sudo_register_ok_neuron(deps: DepsMut, env: Env, netuid: u16, hotkey: &str, coldkey: &str) { +pub fn sudo_register_ok_neuron(deps: DepsMut, _env: Env, netuid: u16, hotkey: &str, coldkey: &str) { let msg = ExecuteMsg::SudoRegister { netuid, hotkey: hotkey.to_string(), @@ -311,7 +311,7 @@ pub fn add_network(store: &mut dyn Storage, netuid: u16, tempo: u16, _modality: } // TODO revisit block increasing logic before or after step -pub fn step_block(mut deps: DepsMut, mut env: &mut Env) -> Result { +pub fn step_block(mut deps: DepsMut, env: &mut Env) -> Result { env.block.height += 1; let result = execute( deps.branch(), @@ -336,7 +336,7 @@ pub fn step_block(mut deps: DepsMut, mut env: &mut Env) -> Result Result { while env.block.height < block_number { diff --git a/src/tests/graph.rs b/src/tests/graph.rs index 1c5043f..bcc9b86 100644 --- a/src/tests/graph.rs +++ b/src/tests/graph.rs @@ -38,7 +38,6 @@ struct UserOutLink { #[test] pub fn test() { - #[rustfmt::skip] let user_out_links = vec![ UserOutLink { user_id: 1, out_link: 1 }, @@ -90,7 +89,7 @@ pub fn test() { println!("Sparse Matrix: : {:?}", &sparseWeightsMatrix); - let mut active_stake: Vec = vec![ + let active_stake: Vec = vec![ I32F32::from_num(0), I32F32::from_num(2000u16), I32F32::from_num(3000u16), diff --git a/src/tests/root.rs b/src/tests/root.rs index 8487acc..e78abe8 100644 --- a/src/tests/root.rs +++ b/src/tests/root.rs @@ -24,7 +24,7 @@ use crate::ContractError; #[test] fn test_root_register_network_exist() { - let (mut deps, mut env) = instantiate_contract(); + let (mut deps, env) = instantiate_contract(); let hotkey_account_id = "addr1"; let coldkey_account_id = "addr667"; @@ -43,7 +43,7 @@ fn test_root_register_network_exist() { #[test] fn test_root_register_normal_on_root_fails() { - let (mut deps, mut env) = instantiate_contract(); + let (mut deps, env) = instantiate_contract(); // Test fails because normal registrations are not allowed // on the root network. @@ -90,7 +90,7 @@ fn test_root_register_normal_on_root_fails() { #[test] fn test_root_register_stake_based_pruning_works() { - let (mut deps, mut env) = instantiate_contract(); + let (mut deps, env) = instantiate_contract(); // Add two networks. let root_netuid: u16 = 0; @@ -540,28 +540,28 @@ fn test_root_subnet_creation_deletion() { // // last_lock: 100000000000, min_lock: 100000000000, last_lock_block: 1, lock_reduction_interval: 2, current_block: 1, mult: 2 lock_cost: 200000000000 assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 200_000_000_000 + 20_000_000_000 ); // Doubles from previous subnet creation step_block(deps.as_mut(), &mut env).unwrap(); // last_lock: 100000000000, min_lock: 100000000000, last_lock_block: 1, lock_reduction_interval: 2, current_block: 2, mult: 2 lock_cost: 150000000000 assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 150_000_000_000 + 15_000_000_000 ); // Reduced by 50% step_block(deps.as_mut(), &mut env).unwrap(); // last_lock: 100000000000, min_lock: 100000000000, last_lock_block: 1, lock_reduction_interval: 2, current_block: 3, mult: 2 lock_cost: 100000000000 assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 100_000_000_000 + 10_000_000_000 ); // Reduced another 50% step_block(deps.as_mut(), &mut env).unwrap(); // last_lock: 100000000000, min_lock: 100000000000, last_lock_block: 1, lock_reduction_interval: 2, current_block: 4, mult: 2 lock_cost: 100000000000 assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 100_000_000_000 + 10_000_000_000 ); // Reaches min value assert_eq!( register_network(deps.as_mut(), env.clone(), owner).is_ok(), @@ -570,7 +570,7 @@ fn test_root_subnet_creation_deletion() { // last_lock: 100000000000, min_lock: 100000000000, last_lock_block: 4, lock_reduction_interval: 2, current_block: 4, mult: 2 lock_cost: 200000000000 assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 200_000_000_000 + 20_000_000_000 ); // Doubles from previous subnet creation step_block(deps.as_mut(), &mut env).unwrap(); @@ -582,7 +582,7 @@ fn test_root_subnet_creation_deletion() { // last_lock: 150000000000, min_lock: 100000000000, last_lock_block: 5, lock_reduction_interval: 2, current_block: 5, mult: 2 lock_cost: 300000000000 assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 300_000_000_000 + 30_000_000_000 ); // Doubles from previous subnet creation step_block(deps.as_mut(), &mut env).unwrap(); @@ -594,7 +594,7 @@ fn test_root_subnet_creation_deletion() { // last_lock: 225000000000, min_lock: 100000000000, last_lock_block: 6, lock_reduction_interval: 2, current_block: 6, mult: 2 lock_cost: 450000000000 assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 450_000_000_000 + 45_000_000_000 ); // Increasing step_block(deps.as_mut(), &mut env).unwrap(); @@ -606,7 +606,7 @@ fn test_root_subnet_creation_deletion() { // last_lock: 337500000000, min_lock: 100000000000, last_lock_block: 7, lock_reduction_interval: 2, current_block: 7, mult: 2 lock_cost: 675000000000 assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 675_000_000_000 + 67_500_000_000 ); // Increasing. assert_eq!( register_network(deps.as_mut(), env.clone(), owner).is_ok(), @@ -615,7 +615,7 @@ fn test_root_subnet_creation_deletion() { // last_lock: 337500000000, min_lock: 100000000000, last_lock_block: 7, lock_reduction_interval: 2, current_block: 7, mult: 2 lock_cost: 675000000000 assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 1_350_000_000_000 + 135_000_000_000 ); // Double increasing. assert_eq!( register_network(deps.as_mut(), env.clone(), owner).is_ok(), @@ -623,32 +623,32 @@ fn test_root_subnet_creation_deletion() { ); assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 2_700_000_000_000 + 270_000_000_000 ); // Double increasing again. // Now drop it like its hot to min again. step_block(deps.as_mut(), &mut env).unwrap(); assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 2_025_000_000_000 + 202_500_000_000 ); // 675_000_000_000 decreasing. step_block(deps.as_mut(), &mut env).unwrap(); assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 1_350_000_000_000 + 135_000_000_000 ); // 675_000_000_000 decreasing. step_block(deps.as_mut(), &mut env).unwrap(); assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 675_000_000_000 + 67_500_000_000 ); // 675_000_000_000 decreasing. step_block(deps.as_mut(), &mut env).unwrap(); assert_eq!( get_network_lock_cost(&deps.storage, &deps.api, env.block.height).unwrap(), - 100_000_000_000 + 10_000_000_000 ); // 675_000_000_000 decreasing with 100000000000 min } diff --git a/src/tests/serving.rs b/src/tests/serving.rs index fd88bf3..6b292bb 100644 --- a/src/tests/serving.rs +++ b/src/tests/serving.rs @@ -26,7 +26,7 @@ mod test { } #[test] fn test_serving_ok() { - let (mut deps, mut env) = instantiate_contract(); + let (mut deps, env) = instantiate_contract(); let hotkey_account_id = "addr1"; let netuid: u16 = 1; @@ -77,7 +77,7 @@ fn test_serving_ok() { #[test] fn test_serving_set_metadata_update() { - let (mut deps, mut env) = instantiate_contract(); + let (mut deps, env) = instantiate_contract(); let hotkey_account_id = "addr1"; let netuid: u16 = 1; @@ -323,7 +323,7 @@ fn test_axon_invalid_port() { #[test] fn test_prometheus_serving_ok() { - let (mut deps, mut env) = instantiate_contract(); + let (mut deps, env) = instantiate_contract(); let hotkey_account_id = "addr1"; let netuid: u16 = 1; @@ -369,7 +369,7 @@ fn test_prometheus_serving_ok() { #[test] fn test_prometheus_serving_set_metadata_update() { - let (mut deps, mut env) = instantiate_contract(); + let (mut deps, env) = instantiate_contract(); let hotkey_account_id = "addr1"; let netuid: u16 = 1; diff --git a/src/tests/uids.rs b/src/tests/uids.rs index 402efc0..0433847 100644 --- a/src/tests/uids.rs +++ b/src/tests/uids.rs @@ -21,7 +21,7 @@ use crate::uids::{ #[test] fn test_replace_neuron() { - let (mut deps, mut env) = instantiate_contract(); + let (mut deps, env) = instantiate_contract(); let netuid: u16 = 1; let tempo: u16 = 13; @@ -94,12 +94,12 @@ fn test_replace_neuron() { &deps.storage, &Addr::unchecked(new_hotkey_account_id), )); - assert_eq!(curr_hotkey, new_hotkey_account_id.clone()); + assert_eq!(curr_hotkey, new_hotkey_account_id); } #[test] fn test_replace_neuron_multiple_subnets() { - let (mut deps, mut env) = instantiate_contract(); + let (mut deps, env) = instantiate_contract(); let block_number: u64 = 0; let netuid: u16 = 1; @@ -125,7 +125,7 @@ fn test_replace_neuron_multiple_subnets() { netuid1, block_number, 111111 * 5, - &hotkey_account_id.clone(), + &hotkey_account_id, ); let coldkey_account_id = "addr1234"; @@ -208,7 +208,7 @@ fn test_replace_neuron_multiple_subnets() { #[test] fn test_replace_neuron_multiple_subnets_unstake_all() { - let (mut deps, mut env) = instantiate_contract(); + let (mut deps, env) = instantiate_contract(); let block_number: u64 = 0; let netuid: u16 = 1; @@ -235,7 +235,7 @@ fn test_replace_neuron_multiple_subnets_unstake_all() { netuid1, block_number, 111111 * 5, - &hotkey_account_id.clone(), + &hotkey_account_id, ); let coldkey_account_id = "1234"; diff --git a/src/tests/weights.rs b/src/tests/weights.rs index 7bad9df..c09cb30 100644 --- a/src/tests/weights.rs +++ b/src/tests/weights.rs @@ -1,5 +1,5 @@ use cosmwasm_std::Addr; -use cw_multi_test::Executor; + use substrate_fixed::types::I32F32; use crate::epoch::get_weights; @@ -332,7 +332,7 @@ fn test_weights_err_has_duplicate_ids() { register_ok_neuron(deps.as_mut(), env.clone(), netuid, "addr1", "addr1", 100000).is_ok(), true ); - let neuron_uid = + let _neuron_uid = get_uid_for_net_and_hotkey(&deps.storage, netuid, &Addr::unchecked("addr1")).unwrap(); // uid 2 @@ -340,7 +340,7 @@ fn test_weights_err_has_duplicate_ids() { register_ok_neuron(deps.as_mut(), env.clone(), netuid, "addr2", "addr2", 100000).is_ok(), true ); - let neuron_uid = + let _neuron_uid = get_uid_for_net_and_hotkey(&deps.storage, netuid, &Addr::unchecked("addr2")).unwrap(); // uid 3 @@ -348,7 +348,7 @@ fn test_weights_err_has_duplicate_ids() { register_ok_neuron(deps.as_mut(), env.clone(), netuid, "addr3", "addr3", 100000).is_ok(), true ); - let neuron_uid = + let _neuron_uid = get_uid_for_net_and_hotkey(&deps.storage, netuid, &Addr::unchecked("addr3")).unwrap(); let weights_keys: Vec = vec![1, 1, 1]; // Contains duplicates @@ -457,7 +457,7 @@ fn test_set_weights_err_not_active() { .is_ok(), true ); - let neuron_uid = + let _neuron_uid = get_uid_for_net_and_hotkey(&deps.storage, netuid, &Addr::unchecked("addr666")).unwrap(); let weights_keys: Vec = vec![0]; // Uid 0 is valid. @@ -731,13 +731,13 @@ fn test_set_weights_sum_larger_than_u16_max() { #[test] fn test_check_length_allows_singleton() { - let (mut deps, env) = instantiate_contract(); + let (mut deps, _) = instantiate_contract(); let netuid = 2; let tempo: u16 = 13; add_network(&mut deps.storage, netuid, tempo, 0); - let hotkey_account = Addr::unchecked("addr1"); + let _hotkey_account = Addr::unchecked("addr1"); let max_allowed: u16 = 1; let min_allowed_weights = max_allowed; @@ -756,13 +756,13 @@ fn test_check_length_allows_singleton() { #[test] fn test_check_length_weights_length_exceeds_min_allowed() { - let (mut deps, env) = instantiate_contract(); + let (mut deps, _env) = instantiate_contract(); let netuid = 2; let tempo: u16 = 13; add_network(&mut deps.storage, netuid, tempo, 0); - let hotkey_account = Addr::unchecked("addr1"); + let _hotkey_account = Addr::unchecked("addr1"); let max_allowed: u16 = 3; let min_allowed_weights = max_allowed; @@ -863,7 +863,7 @@ fn test_normalize_weights_does_not_mutate_when_sum_not_zero() { #[test] fn test_max_weight_limited_allow_self_weights_to_exceed_max_weight_limit() { - let (mut deps, env) = instantiate_contract(); + let (mut deps, _env) = instantiate_contract(); let netuid = 2; let tempo: u16 = 13; @@ -886,7 +886,7 @@ fn test_max_weight_limited_allow_self_weights_to_exceed_max_weight_limit() { #[test] fn test_max_weight_limited_when_weight_limit_is_u16_max() { - let (mut deps, env) = instantiate_contract(); + let (mut deps, _env) = instantiate_contract(); let netuid = 2; let tempo: u16 = 13; @@ -910,7 +910,7 @@ fn test_max_weight_limited_when_weight_limit_is_u16_max() { #[test] fn test_max_weight_limited_when_max_weight_is_within_limit() { - let (mut deps, env) = instantiate_contract(); + let (mut deps, _env) = instantiate_contract(); let netuid = 2; let tempo: u16 = 13; @@ -935,7 +935,7 @@ fn test_max_weight_limited_when_max_weight_is_within_limit() { #[test] fn test_max_weight_limited_when_guard_checks_are_not_triggered() { - let (mut deps, env) = instantiate_contract(); + let (mut deps, _env) = instantiate_contract(); let netuid = 2; let tempo: u16 = 13; @@ -1019,7 +1019,7 @@ fn test_check_len_uids_within_allowed_within_network_pool() { let tempo: u16 = 13; add_network(&mut deps.storage, netuid, tempo, 0); - let max_registrations_per_block: u16 = 100; + let _max_registrations_per_block: u16 = 100; assert_eq!( register_ok_neuron(deps.as_mut(), env.clone(), netuid, "addr1", "addr1", 0).is_ok(), @@ -1055,7 +1055,7 @@ fn test_check_len_uids_within_allowed_not_within_network_pool() { let tempo: u16 = 13; add_network(&mut deps.storage, netuid, tempo, 0); - let max_registrations_per_block: u16 = 100; + let _max_registrations_per_block: u16 = 100; assert_eq!( register_ok_neuron(deps.as_mut(), env.clone(), netuid, "addr1", "addr1", 0).is_ok(), @@ -1070,7 +1070,7 @@ fn test_check_len_uids_within_allowed_not_within_network_pool() { true ); - let max_allowed = get_subnetwork_n(&deps.storage, netuid); + let _max_allowed = get_subnetwork_n(&deps.storage, netuid); let max_default_allowed = 256; // set during add_network as default let uids: Vec = Vec::from_iter((0..(max_default_allowed + 1)).map(|uid| uid)); diff --git a/src/utils.rs b/src/utils.rs index 24dea72..149a199 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -10,11 +10,11 @@ use crate::state::{ EMISSION_VALUES, IMMUNITY_PERIOD, INCENTIVE, KAPPA, LAST_ADJUSTMENT_BLOCK, LAST_MECHANISM_STEP_BLOCK, LAST_TX_BLOCK, LAST_UPDATE, MAX_ALLOWED_UIDS, MAX_ALLOWED_VALIDATORS, MAX_BURN, MAX_DIFFICULTY, MAX_REGISTRATION_PER_BLOCK, - MAX_WEIGHTS_LIMIT, MIN_ALLOWED_WEIGHTS, MIN_BURN, MIN_DIFFICULTY, NETWORK_IMMUNITY_PERIOD, - NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_LOCK_COST, NETWORK_RATE_LIMIT, - NETWORK_REGISTRATION_ALLOWED, PENDING_EMISSION, POW_REGISTRATIONS_THIS_INTERVAL, - PRUNING_SCORES, RANK, RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, - REGISTRATIONS_THIS_INTERVAL, RHO, ROOT, SCALING_LAW_POWER, SERVING_RATE_LIMIT, SUBNETWORK_N, + MAX_WEIGHTS_LIMIT, METADATA, MIN_ALLOWED_WEIGHTS, MIN_BURN, MIN_DIFFICULTY, + NETWORK_IMMUNITY_PERIOD, NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_LOCK_COST, + NETWORK_RATE_LIMIT, NETWORK_REGISTRATION_ALLOWED, PENDING_EMISSION, + POW_REGISTRATIONS_THIS_INTERVAL, PRUNING_SCORES, RANK, RAO_RECYCLED_FOR_REGISTRATION, + REGISTRATIONS_THIS_BLOCK, REGISTRATIONS_THIS_INTERVAL, RHO, ROOT, SERVING_RATE_LIMIT, SUBNET_LIMIT, SUBNET_LOCKED, SUBNET_OWNER, SUBNET_OWNER_CUT, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_ISSUANCE, TRUST, TX_RATE_LIMIT, VALIDATOR_PERMIT, VALIDATOR_PRUNE_LEN, VALIDATOR_TRUST, WEIGHTS_SET_RATE_LIMIT, WEIGHTS_VERSION_KEY, @@ -785,44 +785,6 @@ pub fn do_sudo_set_validator_prune_len( .add_attribute("validator_prune_len", format!("{}", validator_prune_len))) } -#[cfg(test)] -pub fn get_scaling_law_power(store: &dyn Storage, netuid: u16) -> u16 { - SCALING_LAW_POWER.load(store, netuid).unwrap() -} - -pub fn do_sudo_set_scaling_law_power( - deps: DepsMut, - _env: Env, - info: MessageInfo, - netuid: u16, - scaling_law_power: u16, -) -> Result { - ensure_root(deps.storage, &info.sender)?; - - ensure!( - if_subnet_exist(deps.storage, netuid), - ContractError::NetworkDoesNotExist {} - ); - - // The scaling law power must be between 0 and 100 => 0% and 100% - ensure!( - scaling_law_power > 100, - ContractError::StorageValueOutOfRange {} - ); - - SCALING_LAW_POWER.save(deps.storage, netuid, &scaling_law_power)?; - - deps.api.debug(&format!( - "🛸 ScalingLawPowerSet ( netuid: {:?} scaling_law_power: {:?} ) ", - netuid, scaling_law_power - )); - - Ok(Response::default() - .add_attribute("active", "scaling_law_power_set") - .add_attribute("netuid", format!("{}", netuid)) - .add_attribute("scaling_law_power", format!("{}", scaling_law_power))) -} - pub fn get_max_weight_limit(store: &dyn Storage, netuid: u16) -> u16 { MAX_WEIGHTS_LIMIT.load(store, netuid).unwrap() } @@ -1624,5 +1586,23 @@ pub fn do_sudo_set_block_emission( Ok(Response::default() .add_attribute("action", "block_emission_set") - .add_attribute("netuid", format!("{}", emission))) + .add_attribute("emission", format!("{}", emission))) +} + +pub fn do_sudo_set_subnet_metadata( + deps: DepsMut, + _env: Env, + info: MessageInfo, + netuid: u16, + particle: String, +) -> Result { + ensure_subnet_owner_or_root(deps.storage, &info.sender, netuid)?; + ensure!(particle.len() == 46, ContractError::MetadataSizeError {}); + + METADATA.save(deps.storage, netuid, &particle)?; + + Ok(Response::default() + .add_attribute("action", "metadata_set") + .add_attribute("netuid", format!("{}", netuid)) + .add_attribute("metadata", format!("{}", particle))) }