From 46062d9a69700b607371aa0f1a85251d3de11f6c Mon Sep 17 00:00:00 2001 From: open-junius Date: Wed, 11 Dec 2024 23:21:36 +0800 Subject: [PATCH 01/14] get and set all hyperparameters --- runtime/src/precompiles/solidity/subnet.abi | 80 ++-- runtime/src/precompiles/solidity/subnet.sol | 4 +- runtime/src/precompiles/subnet.rs | 421 +++++++++++++++++++- 3 files changed, 472 insertions(+), 33 deletions(-) diff --git a/runtime/src/precompiles/solidity/subnet.abi b/runtime/src/precompiles/solidity/subnet.abi index a89cf91f1..d926f23c9 100644 --- a/runtime/src/precompiles/solidity/subnet.abi +++ b/runtime/src/precompiles/solidity/subnet.abi @@ -1,32 +1,50 @@ [ - { - "inputs": [ - { - "internalType": "bytes", - "name": "subnetName", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "githubRepo", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "subnetContact", - "type": "bytes" - } - ], - "name": "registerNetwork", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [], - "name": "registerNetwork", - "outputs": [], - "stateMutability": "payable", - "type": "function" - } -] \ No newline at end of file + { + "inputs": [ + { + "internalType": "bytes", + "name": "subnetName", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "githubRepo", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "subnetContact", + "type": "bytes" + } + ], + "name": "registerNetwork", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "registerNetwork", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "neruid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "servingRateLimit", + "type": "uint64" + } + ], + "name": "setServingRateLimit", + "outputs": [], + "stateMutability": "payable", + "type": "function" + } + ] \ No newline at end of file diff --git a/runtime/src/precompiles/solidity/subnet.sol b/runtime/src/precompiles/solidity/subnet.sol index e2857ad63..fc0c3ab07 100644 --- a/runtime/src/precompiles/solidity/subnet.sol +++ b/runtime/src/precompiles/solidity/subnet.sol @@ -6,5 +6,7 @@ interface ISubnet { /// Registers a new network without specifying details. function registerNetwork() external payable; /// Registers a new network with specified subnet name, GitHub repository, and contact information. - function registerNetwork(bytes subnetName, bytes githubRepo, bytes subnetContact) external payable; + function registerNetwork(bytes memory subnetName, bytes memory githubRepo, bytes memory subnetContact) external payable; + + function setServingRateLimit(uint16 neruid, uint64 servingRateLimit) external payable; } \ No newline at end of file diff --git a/runtime/src/precompiles/subnet.rs b/runtime/src/precompiles/subnet.rs index 9230a01e9..dc74b0a4a 100644 --- a/runtime/src/precompiles/subnet.rs +++ b/runtime/src/precompiles/subnet.rs @@ -33,6 +33,72 @@ impl SubnetPrecompile { id if id == get_method_id("registerNetwork()") => { Self::register_network(handle, &[0_u8; 0]) } + id if id == get_method_id("setServingRateLimit(uint16,uint64)") => { + Self::set_serving_rate_limit(handle, &method_input) + } + id if id == get_method_id("setMinDifficulty(uint16,uint64)") => { + Self::set_min_difficulty(handle, &method_input) + } + id if id == get_method_id("setMaxDifficulty(uint16,uint64)") => { + Self::set_max_difficulty(handle, &method_input) + } + id if id == get_method_id("setWeightsVersionKey(uint16,uint64)") => { + Self::set_weights_version_key(handle, &method_input) + } + id if id == get_method_id("setWeightsSetRateLimit(uint16,uint64)") => { + Self::set_weights_set_rate_limit(handle, &method_input) + } + id if id == get_method_id("setServingRateLimit(uint16,uint64)") => { + Self::set_adjustment_alpha(handle, &method_input) + } + id if id == get_method_id("setServingRateLimit(uint16,uint64)") => { + Self::set_max_weight_limit(handle, &method_input) + } + id if id == get_method_id("setServingRateLimit(uint16,uint64)") => { + Self::set_immunity_period(handle, &method_input) + } + id if id == get_method_id("setMinAllowedWeights(uint16,uint16)") => { + Self::set_min_allowed_weights(handle, &method_input) + } + id if id == get_method_id("setKappa(uint16,uint16)") => { + Self::set_kappa(handle, &method_input) + } + id if id == get_method_id("setRho(uint16,uint16)") => { + Self::set_rho(handle, &method_input) + } + id if id == get_method_id("setActivityCutoff(uint16,uint16)") => { + Self::set_activity_cutoff(handle, &method_input) + } + id if id == get_method_id("set_NetworkRegistrationAllowed(uint16,bool)") => { + Self::set_network_registration_allowed(handle, &method_input) + } + id if id == get_method_id("setNetworkPowRegistrationAllowed(uint16,bool)") => { + Self::set_network_pow_registration_allowed(handle, &method_input) + } + id if id == get_method_id("setMinBurn(uint16,uint64)") => { + Self::set_min_burn(handle, &method_input) + } + id if id == get_method_id("setMaxBurn(uint16,uint64)") => { + Self::set_max_burn(handle, &method_input) + } + id if id == get_method_id("setDifficulty(uint16,uint64)") => { + Self::set_difficulty(handle, &method_input) + } + id if id == get_method_id("setBondsMovingAverage(uint16,uint64)") => { + Self::set_bonds_moving_average(handle, &method_input) + } + id if id == get_method_id("setCommitRevealWeightsEnabled(uint16,bool)") => { + Self::set_commit_reveal_weights_enabled(handle, &method_input) + } + id if id == get_method_id("setLiquidAlphaEnabled(uint16,bool)") => { + Self::set_liquid_alpha_enabled(handle, &method_input) + } + id if id == get_method_id("setAlphaValues(uint16,uint16,uint16)") => { + Self::set_alpha_values(handle, &method_input) + } + id if id == get_method_id("setCommitRevealWeightsInterval(uint16,uint64)") => { + Self::set_commit_reveal_weights_interval(handle, &method_input) + } _ => Err(PrecompileFailure::Error { exit_status: ExitError::InvalidRange, }), @@ -64,7 +130,287 @@ impl SubnetPrecompile { ) }; - // Dispatch the register_network call + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_serving_rate_limit(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, serving_rate_limit) = Self::parse_netuid_u64_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_serving_rate_limit { + netuid, + serving_rate_limit, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_min_difficulty(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, min_difficulty) = Self::parse_netuid_u64_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_min_difficulty { + netuid, + min_difficulty, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_max_difficulty(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, max_difficulty) = Self::parse_netuid_u64_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_max_difficulty { + netuid, + max_difficulty, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_weights_version_key( + handle: &mut impl PrecompileHandle, + data: &[u8], + ) -> PrecompileResult { + let (netuid, weights_version_key) = Self::parse_netuid_u64_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_weights_version_key { + netuid, + weights_version_key, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_weights_set_rate_limit( + handle: &mut impl PrecompileHandle, + data: &[u8], + ) -> PrecompileResult { + let (netuid, weights_set_rate_limit) = Self::parse_netuid_u64_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_weights_set_rate_limit { + netuid, + weights_set_rate_limit, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_adjustment_alpha(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, adjustment_alpha) = Self::parse_netuid_u64_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_adjustment_alpha { + netuid, + adjustment_alpha, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_max_weight_limit(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, max_weight_limit) = Self::parse_netuid_u16_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_max_weight_limit { + netuid, + max_weight_limit, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_immunity_period(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, immunity_period) = Self::parse_netuid_u16_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_immunity_period { + netuid, + immunity_period, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_min_allowed_weights( + handle: &mut impl PrecompileHandle, + data: &[u8], + ) -> PrecompileResult { + let (netuid, min_allowed_weights) = Self::parse_netuid_u16_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_min_allowed_weights { + netuid, + min_allowed_weights, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_kappa(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, kappa) = Self::parse_netuid_u16_parameter(data)?; + let call = RuntimeCall::AdminUtils(pallet_admin_utils::Call::::sudo_set_kappa { + netuid, + kappa, + }); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_rho(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, rho) = Self::parse_netuid_u16_parameter(data)?; + let call = RuntimeCall::AdminUtils(pallet_admin_utils::Call::::sudo_set_rho { + netuid, + rho, + }); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_activity_cutoff(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, activity_cutoff) = Self::parse_netuid_u16_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_activity_cutoff { + netuid, + activity_cutoff, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_network_registration_allowed( + handle: &mut impl PrecompileHandle, + data: &[u8], + ) -> PrecompileResult { + let (netuid, registration_allowed) = Self::parse_netuid_bool_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_network_registration_allowed { + netuid, + registration_allowed, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_network_pow_registration_allowed( + handle: &mut impl PrecompileHandle, + data: &[u8], + ) -> PrecompileResult { + let (netuid, registration_allowed) = Self::parse_netuid_bool_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_network_pow_registration_allowed { + netuid, + registration_allowed, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_min_burn(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, min_burn) = Self::parse_netuid_u64_parameter(data)?; + let call = + RuntimeCall::AdminUtils(pallet_admin_utils::Call::::sudo_set_min_burn { + netuid, + min_burn, + }); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_max_burn(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, max_burn) = Self::parse_netuid_u64_parameter(data)?; + let call = + RuntimeCall::AdminUtils(pallet_admin_utils::Call::::sudo_set_max_burn { + netuid, + max_burn, + }); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_difficulty(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, difficulty) = Self::parse_netuid_u64_parameter(data)?; + let call = + RuntimeCall::AdminUtils(pallet_admin_utils::Call::::sudo_set_difficulty { + netuid, + difficulty, + }); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_bonds_moving_average( + handle: &mut impl PrecompileHandle, + data: &[u8], + ) -> PrecompileResult { + let (netuid, bonds_moving_average) = Self::parse_netuid_u64_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_bonds_moving_average { + netuid, + bonds_moving_average, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_commit_reveal_weights_enabled( + handle: &mut impl PrecompileHandle, + data: &[u8], + ) -> PrecompileResult { + let (netuid, enabled) = Self::parse_netuid_bool_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_commit_reveal_weights_enabled { + netuid, + enabled, + }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_liquid_alpha_enabled( + handle: &mut impl PrecompileHandle, + data: &[u8], + ) -> PrecompileResult { + let (netuid, enabled) = Self::parse_netuid_bool_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_liquid_alpha_enabled { netuid, enabled }, + ); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_alpha_values(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { + let (netuid, alpha_low, alpha_high) = Self::parse_netuid_u16_u16_parameter(data)?; + let call = + RuntimeCall::AdminUtils(pallet_admin_utils::Call::::sudo_set_alpha_values { + netuid, + alpha_low, + alpha_high, + }); + + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + } + + fn set_commit_reveal_weights_interval( + handle: &mut impl PrecompileHandle, + data: &[u8], + ) -> PrecompileResult { + let (netuid, interval) = Self::parse_netuid_u64_parameter(data)?; + let call = RuntimeCall::AdminUtils( + pallet_admin_utils::Call::::sudo_set_commit_reveal_weights_interval { + netuid, + interval, + }, + ); + dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } @@ -130,4 +476,77 @@ impl SubnetPrecompile { Ok((name_vec, repo_vec, contact_vec)) } + + fn parse_netuid_u64_parameter(data: &[u8]) -> Result<(u16, u64), PrecompileFailure> { + if data.len() < 64 { + return Err(PrecompileFailure::Error { + exit_status: ExitError::InvalidRange, + }); + } + let mut netuid_vec = [0u8; 2]; + netuid_vec.copy_from_slice(get_slice(data, 30, 32)?); + let netuid = u16::from_be_bytes(netuid_vec); + + let mut parameter_vec = [0u8; 8]; + parameter_vec.copy_from_slice(get_slice(data, 56, 64)?); + let parameter = u64::from_be_bytes(parameter_vec); + + Ok((netuid, parameter)) + } + + fn parse_netuid_u16_parameter(data: &[u8]) -> Result<(u16, u16), PrecompileFailure> { + if data.len() < 64 { + return Err(PrecompileFailure::Error { + exit_status: ExitError::InvalidRange, + }); + } + let mut netuid_vec = [0u8; 2]; + netuid_vec.copy_from_slice(get_slice(data, 30, 32)?); + let netuid = u16::from_be_bytes(netuid_vec); + + let mut parameter_vec = [0u8; 2]; + parameter_vec.copy_from_slice(get_slice(data, 62, 64)?); + let parameter = u16::from_be_bytes(parameter_vec); + + Ok((netuid, parameter)) + } + + fn parse_netuid_u16_u16_parameter(data: &[u8]) -> Result<(u16, u16, u16), PrecompileFailure> { + if data.len() < 64 { + return Err(PrecompileFailure::Error { + exit_status: ExitError::InvalidRange, + }); + } + let mut netuid_vec = [0u8; 2]; + netuid_vec.copy_from_slice(get_slice(data, 30, 32)?); + let netuid = u16::from_be_bytes(netuid_vec); + + let mut parameter_1_vec = [0u8; 2]; + parameter_1_vec.copy_from_slice(get_slice(data, 62, 64)?); + let parameter_1 = u16::from_be_bytes(parameter_1_vec); + + let mut parameter_2_vec = [0u8; 2]; + parameter_2_vec.copy_from_slice(get_slice(data, 94, 96)?); + let parameter_2 = u16::from_be_bytes(parameter_2_vec); + + Ok((netuid, parameter_1, parameter_2)) + } + + fn parse_netuid_bool_parameter(data: &[u8]) -> Result<(u16, bool), PrecompileFailure> { + if data.len() < 64 { + return Err(PrecompileFailure::Error { + exit_status: ExitError::InvalidRange, + }); + } + let mut netuid_vec = [0u8; 2]; + netuid_vec.copy_from_slice(get_slice(data, 30, 32)?); + let netuid = u16::from_be_bytes(netuid_vec); + + let mut parameter_vec = [0_u8]; + parameter_vec.copy_from_slice(get_slice(data, 63, 64)?); + + let parameter = parameter_vec[0] != 0; + + Ok((netuid, parameter)) + } } From 2810551ee40f58a1ade930dba9b02ebb5ef97c85 Mon Sep 17 00:00:00 2001 From: open-junius Date: Thu, 12 Dec 2024 18:37:30 +0800 Subject: [PATCH 02/14] all get methods --- runtime/src/precompiles/solidity/subnet.abi | 906 ++++++++++++++++++-- runtime/src/precompiles/solidity/subnet.sol | 88 +- runtime/src/precompiles/subnet.rs | 92 +- 3 files changed, 1032 insertions(+), 54 deletions(-) diff --git a/runtime/src/precompiles/solidity/subnet.abi b/runtime/src/precompiles/solidity/subnet.abi index d926f23c9..1c80c7407 100644 --- a/runtime/src/precompiles/solidity/subnet.abi +++ b/runtime/src/precompiles/solidity/subnet.abi @@ -1,50 +1,858 @@ [ - { - "inputs": [ - { - "internalType": "bytes", - "name": "subnetName", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "githubRepo", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "subnetContact", - "type": "bytes" - } - ], - "name": "registerNetwork", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [], - "name": "registerNetwork", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint16", - "name": "neruid", - "type": "uint16" - }, - { - "internalType": "uint64", - "name": "servingRateLimit", - "type": "uint64" - } - ], - "name": "setServingRateLimit", - "outputs": [], - "stateMutability": "payable", - "type": "function" - } - ] \ No newline at end of file + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getAdjustmentAlpha", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getAlphaValues", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getBondsMovingAverage", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getCommitRevealWeightsEnabled", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getDifficulty", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "name": "getImmunityPeriod", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "name": "getKappa", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getMaxBurn", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getMaxDifficulty", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getMaxWeightLimit", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getMinAllowedWeights", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getMinBurn", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getMinDifficulty", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getNetworkRegistrationAllowed", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "name": "getRho", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getServingRateLimit", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getWeightsSetRateLimit", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getWeightsVersionKey", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "subnetName", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "githubRepo", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "subnetContact", + "type": "bytes" + } + ], + "name": "registerNetwork", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "registerNetwork", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "activityCutoff", + "type": "uint16" + } + ], + "name": "setActivityCutoff", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "setActivityCutoff", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "adjustmentAlpha", + "type": "uint64" + } + ], + "name": "setAdjustmentAlpha", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "alphaLow", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "alphaHigh", + "type": "uint16" + } + ], + "name": "setAlphaValues", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "bondsMovingAverage", + "type": "uint64" + } + ], + "name": "setBondsMovingAverage", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "bool", + "name": "commitRevealWeightsEnabled", + "type": "bool" + } + ], + "name": "setCommitRevealWeightsEnabled", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "setCommitRevealWeightsInterval", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "commitRevealWeightsInterval", + "type": "uint64" + } + ], + "name": "setCommitRevealWeightsInterval", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "difficulty", + "type": "uint64" + } + ], + "name": "setDifficulty", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "immunityPeriod", + "type": "uint64" + } + ], + "name": "setImmunityPeriod", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "kappa", + "type": "uint16" + } + ], + "name": "setKappa", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "setLiquidAlphaEnabled", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "bool", + "name": "liquidAlphaEnabled", + "type": "bool" + } + ], + "name": "setLiquidAlphaEnabled", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "maxBurn", + "type": "uint64" + } + ], + "name": "setMaxBurn", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "maxDifficulty", + "type": "uint64" + } + ], + "name": "setMaxDifficulty", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "maxWeightLimit", + "type": "uint64" + } + ], + "name": "setMaxWeightLimit", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "minAllowedWeights", + "type": "uint16" + } + ], + "name": "setMinAllowedWeights", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "minBurn", + "type": "uint64" + } + ], + "name": "setMinBurn", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "minDifficulty", + "type": "uint64" + } + ], + "name": "setMinDifficulty", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "setNetworkPowRegistrationAllowed", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "bool", + "name": "networkPowRegistrationAllowed", + "type": "bool" + } + ], + "name": "setNetworkPowRegistrationAllowed", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "bool", + "name": "networkRegistrationAllowed", + "type": "bool" + } + ], + "name": "setNetworkRegistrationAllowed", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "rho", + "type": "uint16" + } + ], + "name": "setRho", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "servingRateLimit", + "type": "uint64" + } + ], + "name": "setServingRateLimit", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "weightsSetRateLimit", + "type": "uint64" + } + ], + "name": "setWeightsSetRateLimit", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + }, + { + "internalType": "uint64", + "name": "weightsVersionKey", + "type": "uint64" + } + ], + "name": "setWeightsVersionKey", + "outputs": [], + "stateMutability": "payable", + "type": "function" + } +] + + \ No newline at end of file diff --git a/runtime/src/precompiles/solidity/subnet.sol b/runtime/src/precompiles/solidity/subnet.sol index fc0c3ab07..99dac763e 100644 --- a/runtime/src/precompiles/solidity/subnet.sol +++ b/runtime/src/precompiles/solidity/subnet.sol @@ -8,5 +8,91 @@ interface ISubnet { /// Registers a new network with specified subnet name, GitHub repository, and contact information. function registerNetwork(bytes memory subnetName, bytes memory githubRepo, bytes memory subnetContact) external payable; - function setServingRateLimit(uint16 neruid, uint64 servingRateLimit) external payable; + function getServingRateLimit(uint16 netuid) external view returns (uint64); + + function setServingRateLimit(uint16 netuid, uint64 servingRateLimit) external payable; + + function getMinDifficulty(uint16 netuid) external view returns (uint64); + + function setMinDifficulty(uint16 netuid, uint64 minDifficulty) external payable; + + function getMaxDifficulty(uint16 netuid) external view returns (uint64); + + function setMaxDifficulty(uint16 netuid,uint64 maxDifficulty) external payable; + + function getWeightsVersionKey(uint16 netuid) external view returns (uint64); + + function setWeightsVersionKey(uint16 netuid, uint64 weightsVersionKey) external payable; + + function getWeightsSetRateLimit(uint16 netuid) external view returns (uint64); + + function setWeightsSetRateLimit(uint16 netuid, uint64 weightsSetRateLimit) external payable; + + function getAdjustmentAlpha(uint16 netuid) external view returns (uint64); + + function setAdjustmentAlpha(uint16 netuid, uint64 adjustmentAlpha) external payable; + + function getMaxWeightLimit(uint16 netuid) external view returns (uint64); + + function setMaxWeightLimit(uint16 netuid, uint64 maxWeightLimit) external payable; + + function getImmunityPeriod(uint16) external view returns (uint64); + + function setImmunityPeriod(uint16 netuid, uint64 immunityPeriod) external payable; + + function getMinAllowedWeights(uint16 netuid)external view returns (uint16); + + function setMinAllowedWeights(uint16 netuid, uint16 minAllowedWeights) external payable; + + function getKappa(uint16) external view returns (uint16); + + function setKappa(uint16 netuid, uint16 kappa) external payable; + + function getRho(uint16) external view returns (uint16); + + function setRho(uint16 netuid, uint16 rho) external payable; + + function setActivityCutoff(uint16 netuid) external view returns (uint16); + + function setActivityCutoff(uint16 netuid, uint16 activityCutoff) external payable; + + function getNetworkRegistrationAllowed(uint16 netuid) external view returns (bool); + + function setNetworkRegistrationAllowed(uint16 netuid, bool networkRegistrationAllowed) external payable; + + function setNetworkPowRegistrationAllowed(uint16 netuid) external view returns (bool); + + function setNetworkPowRegistrationAllowed(uint16 netuid, bool networkPowRegistrationAllowed) external payable; + + function getMinBurn(uint16 netuid) external view returns (uint64); + + function setMinBurn(uint16 netuid, uint64 minBurn) external payable; + + function getMaxBurn(uint16 netuid) external view returns (uint64); + + function setMaxBurn(uint16 netuid, uint64 maxBurn) external payable; + + function getDifficulty(uint16 netuid) external view returns (uint64); + + function setDifficulty(uint16 netuid, uint64 difficulty) external payable; + + function getBondsMovingAverage(uint16 netuid) external view returns (uint64); + + function setBondsMovingAverage(uint16 netuid, uint64 bondsMovingAverage) external payable; + + function getCommitRevealWeightsEnabled(uint16 netuid) external view returns (bool); + + function setCommitRevealWeightsEnabled(uint16 netuid, bool commitRevealWeightsEnabled) external payable; + + function setLiquidAlphaEnabled(uint16 netuid) external view returns (bool); + + function setLiquidAlphaEnabled(uint16 netuid, bool liquidAlphaEnabled) external payable; + + function getAlphaValues(uint16 netuid) external view returns (uint16, uint16); + + function setAlphaValues(uint16 netuid, uint16 alphaLow, uint16 alphaHigh) external payable; + + function setCommitRevealWeightsInterval(uint16 netuid) external view returns (uint64); + + function setCommitRevealWeightsInterval(uint16 netuid, uint64 commitRevealWeightsInterval) external payable; } \ No newline at end of file diff --git a/runtime/src/precompiles/subnet.rs b/runtime/src/precompiles/subnet.rs index dc74b0a4a..956efbd5c 100644 --- a/runtime/src/precompiles/subnet.rs +++ b/runtime/src/precompiles/subnet.rs @@ -33,69 +33,153 @@ impl SubnetPrecompile { id if id == get_method_id("registerNetwork()") => { Self::register_network(handle, &[0_u8; 0]) } + + id if id == get_method_id("getServingRateLimit(uint16)") => { + Self::get_serving_rate_limit(handle, &method_input) + } id if id == get_method_id("setServingRateLimit(uint16,uint64)") => { Self::set_serving_rate_limit(handle, &method_input) } + + id if id == get_method_id("getMinDifficulty(uint16)") => { + Self::get_min_difficulty(handle, &method_input) + } id if id == get_method_id("setMinDifficulty(uint16,uint64)") => { Self::set_min_difficulty(handle, &method_input) } + + id if id == get_method_id("getMaxDifficulty(uint16)") => { + Self::get_max_difficulty(handle, &method_input) + } id if id == get_method_id("setMaxDifficulty(uint16,uint64)") => { Self::set_max_difficulty(handle, &method_input) } + + id if id == get_method_id("getWeightsVersionKey(uint16)") => { + Self::get_weights_version_key(handle, &method_input) + } id if id == get_method_id("setWeightsVersionKey(uint16,uint64)") => { Self::set_weights_version_key(handle, &method_input) } + + id if id == get_method_id("getWeightsSetRateLimit(uint16,uint64)") => { + Self::get_weights_set_rate_limit(handle, &method_input) + } id if id == get_method_id("setWeightsSetRateLimit(uint16,uint64)") => { Self::set_weights_set_rate_limit(handle, &method_input) } - id if id == get_method_id("setServingRateLimit(uint16,uint64)") => { + + id if id == get_method_id("getAdjustmentAlpha(uint16)") => { + Self::get_adjustment_alpha(handle, &method_input) + } + id if id == get_method_id("setAdjustmentAlpha(uint16,uint64)") => { Self::set_adjustment_alpha(handle, &method_input) } - id if id == get_method_id("setServingRateLimit(uint16,uint64)") => { + + id if id == get_method_id("getMaxWeightLimit(uint16)") => { + Self::get_max_weight_limit(handle, &method_input) + } + id if id == get_method_id("setMaxWeightLimit(uint16,uint64)") => { Self::set_max_weight_limit(handle, &method_input) } - id if id == get_method_id("setServingRateLimit(uint16,uint64)") => { + + id if id == get_method_id("getImmunityPeriod(uint16)") => { + Self::get_immunity_period(handle, &method_input) + } + id if id == get_method_id("setImmunityPeriod(uint16,uint64)") => { Self::set_immunity_period(handle, &method_input) } + + id if id == get_method_id("getMinAllowedWeights(uint16)") => { + Self::get_min_allowed_weights(handle, &method_input) + } id if id == get_method_id("setMinAllowedWeights(uint16,uint16)") => { Self::set_min_allowed_weights(handle, &method_input) } + + id if id == get_method_id("getKappa(uint16)") => Self::get_kappa(handle, &method_input), id if id == get_method_id("setKappa(uint16,uint16)") => { Self::set_kappa(handle, &method_input) } + + id if id == get_method_id("getRho(uint16)") => Self::get_rho(handle, &method_input), id if id == get_method_id("setRho(uint16,uint16)") => { Self::set_rho(handle, &method_input) } + + id if id == get_method_id("getActivityCutoff(uint16)") => { + Self::get_activity_cutoff(handle, &method_input) + } id if id == get_method_id("setActivityCutoff(uint16,uint16)") => { Self::set_activity_cutoff(handle, &method_input) } - id if id == get_method_id("set_NetworkRegistrationAllowed(uint16,bool)") => { + + id if id == get_method_id("getNetworkRegistrationAllowed(uint16)") => { + Self::get_network_registration_allowed(handle, &method_input) + } + id if id == get_method_id("setNetworkRegistrationAllowed(uint16,bool)") => { Self::set_network_registration_allowed(handle, &method_input) } + + id if id == get_method_id("getNetworkPowRegistrationAllowed(uint16)") => { + Self::get_network_pow_registration_allowed(handle, &method_input) + } id if id == get_method_id("setNetworkPowRegistrationAllowed(uint16,bool)") => { Self::set_network_pow_registration_allowed(handle, &method_input) } + + id if id == get_method_id("getMinBurn(uint16)") => { + Self::get_min_burn(handle, &method_input) + } id if id == get_method_id("setMinBurn(uint16,uint64)") => { Self::set_min_burn(handle, &method_input) } + + id if id == get_method_id("getMaxBurn(uint16)") => { + Self::get_max_burn(handle, &method_input) + } id if id == get_method_id("setMaxBurn(uint16,uint64)") => { Self::set_max_burn(handle, &method_input) } + + id if id == get_method_id("getDifficulty(uint16)") => { + Self::get_difficulty(handle, &method_input) + } id if id == get_method_id("setDifficulty(uint16,uint64)") => { Self::set_difficulty(handle, &method_input) } + + id if id == get_method_id("getBondsMovingAverage(uint16)") => { + Self::get_bonds_moving_average(handle, &method_input) + } id if id == get_method_id("setBondsMovingAverage(uint16,uint64)") => { Self::set_bonds_moving_average(handle, &method_input) } + + id if id == get_method_id("getCommitRevealWeightsEnabled(uint16)") => { + Self::get_commit_reveal_weights_enabled(handle, &method_input) + } id if id == get_method_id("setCommitRevealWeightsEnabled(uint16,bool)") => { Self::set_commit_reveal_weights_enabled(handle, &method_input) } + + id if id == get_method_id("getLiquidAlphaEnabled(uint16)") => { + Self::get_liquid_alpha_enabled(handle, &method_input) + } id if id == get_method_id("setLiquidAlphaEnabled(uint16,bool)") => { Self::set_liquid_alpha_enabled(handle, &method_input) } + + id if id == get_method_id("getAlphaValues(uint16)") => { + Self::get_alpha_values(handle, &method_input) + } id if id == get_method_id("setAlphaValues(uint16,uint16,uint16)") => { Self::set_alpha_values(handle, &method_input) } + + id if id == get_method_id("getCommitRevealWeightsInterval(uint16)") => { + Self::get_commit_reveal_weights_interval(handle, &method_input) + } id if id == get_method_id("setCommitRevealWeightsInterval(uint16,uint64)") => { Self::set_commit_reveal_weights_interval(handle, &method_input) } From 3913fba79de84c42a8b56e61523ae6abfc06f5cf Mon Sep 17 00:00:00 2001 From: open-junius Date: Thu, 12 Dec 2024 19:19:31 +0800 Subject: [PATCH 03/14] all get set done --- runtime/src/precompiles/subnet.rs | 399 ++++++++++++++++++++++++++++-- 1 file changed, 372 insertions(+), 27 deletions(-) diff --git a/runtime/src/precompiles/subnet.rs b/runtime/src/precompiles/subnet.rs index 956efbd5c..4b3a943a4 100644 --- a/runtime/src/precompiles/subnet.rs +++ b/runtime/src/precompiles/subnet.rs @@ -1,6 +1,9 @@ use crate::precompiles::{dispatch, get_method_id, get_slice}; use crate::{Runtime, RuntimeCall}; -use pallet_evm::{ExitError, PrecompileFailure, PrecompileHandle, PrecompileResult}; +use pallet_evm::{ + ExitError, ExitSucceed, PrecompileFailure, PrecompileHandle, PrecompileOutput, PrecompileResult, +}; +use sp_core::U256; use sp_std::vec; pub const SUBNET_PRECOMPILE_INDEX: u64 = 2051; @@ -35,150 +38,146 @@ impl SubnetPrecompile { } id if id == get_method_id("getServingRateLimit(uint16)") => { - Self::get_serving_rate_limit(handle, &method_input) + Self::get_serving_rate_limit(&method_input) } id if id == get_method_id("setServingRateLimit(uint16,uint64)") => { Self::set_serving_rate_limit(handle, &method_input) } id if id == get_method_id("getMinDifficulty(uint16)") => { - Self::get_min_difficulty(handle, &method_input) + Self::get_min_difficulty(&method_input) } id if id == get_method_id("setMinDifficulty(uint16,uint64)") => { Self::set_min_difficulty(handle, &method_input) } id if id == get_method_id("getMaxDifficulty(uint16)") => { - Self::get_max_difficulty(handle, &method_input) + Self::get_max_difficulty(&method_input) } id if id == get_method_id("setMaxDifficulty(uint16,uint64)") => { Self::set_max_difficulty(handle, &method_input) } id if id == get_method_id("getWeightsVersionKey(uint16)") => { - Self::get_weights_version_key(handle, &method_input) + Self::get_weights_version_key(&method_input) } id if id == get_method_id("setWeightsVersionKey(uint16,uint64)") => { Self::set_weights_version_key(handle, &method_input) } id if id == get_method_id("getWeightsSetRateLimit(uint16,uint64)") => { - Self::get_weights_set_rate_limit(handle, &method_input) + Self::get_weights_set_rate_limit(&method_input) } id if id == get_method_id("setWeightsSetRateLimit(uint16,uint64)") => { Self::set_weights_set_rate_limit(handle, &method_input) } id if id == get_method_id("getAdjustmentAlpha(uint16)") => { - Self::get_adjustment_alpha(handle, &method_input) + Self::get_adjustment_alpha(&method_input) } id if id == get_method_id("setAdjustmentAlpha(uint16,uint64)") => { Self::set_adjustment_alpha(handle, &method_input) } id if id == get_method_id("getMaxWeightLimit(uint16)") => { - Self::get_max_weight_limit(handle, &method_input) + Self::get_max_weight_limit(&method_input) } id if id == get_method_id("setMaxWeightLimit(uint16,uint64)") => { Self::set_max_weight_limit(handle, &method_input) } id if id == get_method_id("getImmunityPeriod(uint16)") => { - Self::get_immunity_period(handle, &method_input) + Self::get_immunity_period(&method_input) } id if id == get_method_id("setImmunityPeriod(uint16,uint64)") => { Self::set_immunity_period(handle, &method_input) } id if id == get_method_id("getMinAllowedWeights(uint16)") => { - Self::get_min_allowed_weights(handle, &method_input) + Self::get_min_allowed_weights(&method_input) } id if id == get_method_id("setMinAllowedWeights(uint16,uint16)") => { Self::set_min_allowed_weights(handle, &method_input) } - id if id == get_method_id("getKappa(uint16)") => Self::get_kappa(handle, &method_input), + id if id == get_method_id("getKappa(uint16)") => Self::get_kappa(&method_input), id if id == get_method_id("setKappa(uint16,uint16)") => { Self::set_kappa(handle, &method_input) } - id if id == get_method_id("getRho(uint16)") => Self::get_rho(handle, &method_input), + id if id == get_method_id("getRho(uint16)") => Self::get_rho(&method_input), id if id == get_method_id("setRho(uint16,uint16)") => { Self::set_rho(handle, &method_input) } id if id == get_method_id("getActivityCutoff(uint16)") => { - Self::get_activity_cutoff(handle, &method_input) + Self::get_activity_cutoff(&method_input) } id if id == get_method_id("setActivityCutoff(uint16,uint16)") => { Self::set_activity_cutoff(handle, &method_input) } id if id == get_method_id("getNetworkRegistrationAllowed(uint16)") => { - Self::get_network_registration_allowed(handle, &method_input) + Self::get_network_registration_allowed(&method_input) } id if id == get_method_id("setNetworkRegistrationAllowed(uint16,bool)") => { Self::set_network_registration_allowed(handle, &method_input) } id if id == get_method_id("getNetworkPowRegistrationAllowed(uint16)") => { - Self::get_network_pow_registration_allowed(handle, &method_input) + Self::get_network_pow_registration_allowed(&method_input) } id if id == get_method_id("setNetworkPowRegistrationAllowed(uint16,bool)") => { Self::set_network_pow_registration_allowed(handle, &method_input) } - id if id == get_method_id("getMinBurn(uint16)") => { - Self::get_min_burn(handle, &method_input) - } + id if id == get_method_id("getMinBurn(uint16)") => Self::get_min_burn(&method_input), id if id == get_method_id("setMinBurn(uint16,uint64)") => { Self::set_min_burn(handle, &method_input) } - id if id == get_method_id("getMaxBurn(uint16)") => { - Self::get_max_burn(handle, &method_input) - } + id if id == get_method_id("getMaxBurn(uint16)") => Self::get_max_burn(&method_input), id if id == get_method_id("setMaxBurn(uint16,uint64)") => { Self::set_max_burn(handle, &method_input) } id if id == get_method_id("getDifficulty(uint16)") => { - Self::get_difficulty(handle, &method_input) + Self::get_difficulty(&method_input) } id if id == get_method_id("setDifficulty(uint16,uint64)") => { Self::set_difficulty(handle, &method_input) } id if id == get_method_id("getBondsMovingAverage(uint16)") => { - Self::get_bonds_moving_average(handle, &method_input) + Self::get_bonds_moving_average(&method_input) } id if id == get_method_id("setBondsMovingAverage(uint16,uint64)") => { Self::set_bonds_moving_average(handle, &method_input) } id if id == get_method_id("getCommitRevealWeightsEnabled(uint16)") => { - Self::get_commit_reveal_weights_enabled(handle, &method_input) + Self::get_commit_reveal_weights_enabled(&method_input) } id if id == get_method_id("setCommitRevealWeightsEnabled(uint16,bool)") => { Self::set_commit_reveal_weights_enabled(handle, &method_input) } id if id == get_method_id("getLiquidAlphaEnabled(uint16)") => { - Self::get_liquid_alpha_enabled(handle, &method_input) + Self::get_liquid_alpha_enabled(&method_input) } id if id == get_method_id("setLiquidAlphaEnabled(uint16,bool)") => { Self::set_liquid_alpha_enabled(handle, &method_input) } id if id == get_method_id("getAlphaValues(uint16)") => { - Self::get_alpha_values(handle, &method_input) + Self::get_alpha_values(&method_input) } id if id == get_method_id("setAlphaValues(uint16,uint16,uint16)") => { Self::set_alpha_values(handle, &method_input) } id if id == get_method_id("getCommitRevealWeightsInterval(uint16)") => { - Self::get_commit_reveal_weights_interval(handle, &method_input) + Self::get_commit_reveal_weights_interval(&method_input) } id if id == get_method_id("setCommitRevealWeightsInterval(uint16,uint64)") => { Self::set_commit_reveal_weights_interval(handle, &method_input) @@ -217,6 +216,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_serving_rate_limit(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::ServingRateLimit::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_serving_rate_limit(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, serving_rate_limit) = Self::parse_netuid_u64_parameter(data)?; let call = RuntimeCall::AdminUtils( @@ -229,6 +243,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_min_difficulty(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::MinDifficulty::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_min_difficulty(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, min_difficulty) = Self::parse_netuid_u64_parameter(data)?; let call = RuntimeCall::AdminUtils( @@ -241,6 +270,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_max_difficulty(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::MaxDifficulty::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_max_difficulty(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, max_difficulty) = Self::parse_netuid_u64_parameter(data)?; let call = RuntimeCall::AdminUtils( @@ -253,6 +297,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_weights_version_key(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::WeightsVersionKey::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_weights_version_key( handle: &mut impl PrecompileHandle, data: &[u8], @@ -268,6 +327,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_weights_set_rate_limit(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::WeightsSetRateLimit::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_weights_set_rate_limit( handle: &mut impl PrecompileHandle, data: &[u8], @@ -283,6 +357,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_adjustment_alpha(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::AdjustmentAlpha::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_adjustment_alpha(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, adjustment_alpha) = Self::parse_netuid_u64_parameter(data)?; let call = RuntimeCall::AdminUtils( @@ -295,6 +384,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_max_weight_limit(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::MaxWeightsLimit::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_max_weight_limit(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, max_weight_limit) = Self::parse_netuid_u16_parameter(data)?; let call = RuntimeCall::AdminUtils( @@ -307,6 +411,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_immunity_period(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::ImmunityPeriod::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_immunity_period(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, immunity_period) = Self::parse_netuid_u16_parameter(data)?; let call = RuntimeCall::AdminUtils( @@ -319,6 +438,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_min_allowed_weights(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::MinAllowedWeights::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_min_allowed_weights( handle: &mut impl PrecompileHandle, data: &[u8], @@ -334,6 +468,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_kappa(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::Kappa::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_kappa(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, kappa) = Self::parse_netuid_u16_parameter(data)?; let call = RuntimeCall::AdminUtils(pallet_admin_utils::Call::::sudo_set_kappa { @@ -344,6 +493,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_rho(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::Rho::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_rho(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, rho) = Self::parse_netuid_u16_parameter(data)?; let call = RuntimeCall::AdminUtils(pallet_admin_utils::Call::::sudo_set_rho { @@ -354,6 +518,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_activity_cutoff(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::ActivityCutoff::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_activity_cutoff(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, activity_cutoff) = Self::parse_netuid_u16_parameter(data)?; let call = RuntimeCall::AdminUtils( @@ -366,6 +545,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_network_registration_allowed(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::NetworkRegistrationAllowed::::get(netuid); + + let value_u256 = if value { U256::from(1) } else { U256::from(0) }; + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_network_registration_allowed( handle: &mut impl PrecompileHandle, data: &[u8], @@ -381,6 +575,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_network_pow_registration_allowed(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::NetworkPowRegistrationAllowed::::get(netuid); + + let value_u256 = if value { U256::from(1) } else { U256::from(0) }; + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_network_pow_registration_allowed( handle: &mut impl PrecompileHandle, data: &[u8], @@ -396,6 +605,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_min_burn(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::MinBurn::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_min_burn(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, min_burn) = Self::parse_netuid_u64_parameter(data)?; let call = @@ -407,6 +631,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_max_burn(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::MaxBurn::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_max_burn(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, max_burn) = Self::parse_netuid_u64_parameter(data)?; let call = @@ -418,6 +657,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_difficulty(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::Difficulty::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_difficulty(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, difficulty) = Self::parse_netuid_u64_parameter(data)?; let call = @@ -429,6 +683,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_bonds_moving_average(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::BondsMovingAverage::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_bonds_moving_average( handle: &mut impl PrecompileHandle, data: &[u8], @@ -444,6 +713,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_commit_reveal_weights_enabled(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::CommitRevealWeightsEnabled::::get(netuid); + + let value_u256 = if value { U256::from(1) } else { U256::from(0) }; + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_commit_reveal_weights_enabled( handle: &mut impl PrecompileHandle, data: &[u8], @@ -459,6 +743,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_liquid_alpha_enabled(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::LiquidAlphaOn::::get(netuid); + + let value_u256 = if value { U256::from(1) } else { U256::from(0) }; + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_liquid_alpha_enabled( handle: &mut impl PrecompileHandle, data: &[u8], @@ -471,6 +770,24 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_alpha_values(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let (alpha_low, alpha_high) = pallet_subtensor::AlphaValues::::get(netuid); + + let mut value_u256 = U256::from(alpha_low); + let mut result = [0_u8; 64]; + U256::to_big_endian(&value_u256, &mut result[0..]); + + value_u256 = U256::from(alpha_high); + U256::to_big_endian(&value_u256, &mut result[32..]); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_alpha_values(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult { let (netuid, alpha_low, alpha_high) = Self::parse_netuid_u16_u16_parameter(data)?; let call = @@ -483,6 +800,21 @@ impl SubnetPrecompile { dispatch(handle, call, STAKING_CONTRACT_ADDRESS) } + fn get_commit_reveal_weights_interval(data: &[u8]) -> PrecompileResult { + let netuid = Self::parse_netuid(data)?; + + let value = pallet_subtensor::RevealPeriodEpochs::::get(netuid); + + let value_u256 = U256::from(value); + let mut result = [0_u8; 32]; + U256::to_big_endian(&value_u256, &mut result); + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Returned, + output: result.into(), + }) + } + fn set_commit_reveal_weights_interval( handle: &mut impl PrecompileHandle, data: &[u8], @@ -561,6 +893,19 @@ impl SubnetPrecompile { Ok((name_vec, repo_vec, contact_vec)) } + fn parse_netuid(data: &[u8]) -> Result { + if data.len() < 32 { + return Err(PrecompileFailure::Error { + exit_status: ExitError::InvalidRange, + }); + } + let mut netuid_vec = [0u8; 2]; + netuid_vec.copy_from_slice(get_slice(data, 30, 32)?); + let netuid = u16::from_be_bytes(netuid_vec); + + Ok(netuid) + } + fn parse_netuid_u64_parameter(data: &[u8]) -> Result<(u16, u64), PrecompileFailure> { if data.len() < 64 { return Err(PrecompileFailure::Error { From 8cefb1878fed65f2b242a908106ccb6adb8bb0e2 Mon Sep 17 00:00:00 2001 From: open-junius Date: Thu, 12 Dec 2024 23:29:14 +0800 Subject: [PATCH 04/14] fix bugs --- runtime/src/precompiles/solidity/subnet.abi | 8 ++++---- runtime/src/precompiles/solidity/subnet.sol | 8 ++++---- runtime/src/precompiles/subnet.rs | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/runtime/src/precompiles/solidity/subnet.abi b/runtime/src/precompiles/solidity/subnet.abi index 1c80c7407..d930d0b88 100644 --- a/runtime/src/precompiles/solidity/subnet.abi +++ b/runtime/src/precompiles/solidity/subnet.abi @@ -402,7 +402,7 @@ "type": "uint16" } ], - "name": "setActivityCutoff", + "name": "getActivityCutoff", "outputs": [ { "internalType": "uint16", @@ -498,7 +498,7 @@ "type": "uint16" } ], - "name": "setCommitRevealWeightsInterval", + "name": "getCommitRevealWeightsInterval", "outputs": [ { "internalType": "uint64", @@ -589,7 +589,7 @@ "type": "uint16" } ], - "name": "setLiquidAlphaEnabled", + "name": "getLiquidAlphaEnabled", "outputs": [ { "internalType": "bool", @@ -734,7 +734,7 @@ "type": "uint16" } ], - "name": "setNetworkPowRegistrationAllowed", + "name": "getNetworkPowRegistrationAllowed", "outputs": [ { "internalType": "bool", diff --git a/runtime/src/precompiles/solidity/subnet.sol b/runtime/src/precompiles/solidity/subnet.sol index 99dac763e..5992c7535 100644 --- a/runtime/src/precompiles/solidity/subnet.sol +++ b/runtime/src/precompiles/solidity/subnet.sol @@ -52,7 +52,7 @@ interface ISubnet { function setRho(uint16 netuid, uint16 rho) external payable; - function setActivityCutoff(uint16 netuid) external view returns (uint16); + function getActivityCutoff(uint16 netuid) external view returns (uint16); function setActivityCutoff(uint16 netuid, uint16 activityCutoff) external payable; @@ -60,7 +60,7 @@ interface ISubnet { function setNetworkRegistrationAllowed(uint16 netuid, bool networkRegistrationAllowed) external payable; - function setNetworkPowRegistrationAllowed(uint16 netuid) external view returns (bool); + function getNetworkPowRegistrationAllowed(uint16 netuid) external view returns (bool); function setNetworkPowRegistrationAllowed(uint16 netuid, bool networkPowRegistrationAllowed) external payable; @@ -84,7 +84,7 @@ interface ISubnet { function setCommitRevealWeightsEnabled(uint16 netuid, bool commitRevealWeightsEnabled) external payable; - function setLiquidAlphaEnabled(uint16 netuid) external view returns (bool); + function getLiquidAlphaEnabled(uint16 netuid) external view returns (bool); function setLiquidAlphaEnabled(uint16 netuid, bool liquidAlphaEnabled) external payable; @@ -92,7 +92,7 @@ interface ISubnet { function setAlphaValues(uint16 netuid, uint16 alphaLow, uint16 alphaHigh) external payable; - function setCommitRevealWeightsInterval(uint16 netuid) external view returns (uint64); + function getCommitRevealWeightsInterval(uint16 netuid) external view returns (uint64); function setCommitRevealWeightsInterval(uint16 netuid, uint64 commitRevealWeightsInterval) external payable; } \ No newline at end of file diff --git a/runtime/src/precompiles/subnet.rs b/runtime/src/precompiles/subnet.rs index 4b3a943a4..a57103a39 100644 --- a/runtime/src/precompiles/subnet.rs +++ b/runtime/src/precompiles/subnet.rs @@ -65,7 +65,7 @@ impl SubnetPrecompile { Self::set_weights_version_key(handle, &method_input) } - id if id == get_method_id("getWeightsSetRateLimit(uint16,uint64)") => { + id if id == get_method_id("getWeightsSetRateLimit(uint16)") => { Self::get_weights_set_rate_limit(&method_input) } id if id == get_method_id("setWeightsSetRateLimit(uint16,uint64)") => { @@ -347,6 +347,7 @@ impl SubnetPrecompile { data: &[u8], ) -> PrecompileResult { let (netuid, weights_set_rate_limit) = Self::parse_netuid_u64_parameter(data)?; + let call = RuntimeCall::AdminUtils( pallet_admin_utils::Call::::sudo_set_weights_set_rate_limit { netuid, From 7ba9fc65e21e6c357927e82a76df475273f82122 Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 13 Dec 2024 20:47:24 +0800 Subject: [PATCH 05/14] remove wrong comments --- runtime/src/precompiles/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/src/precompiles/mod.rs b/runtime/src/precompiles/mod.rs index 398a80a05..8f726a251 100644 --- a/runtime/src/precompiles/mod.rs +++ b/runtime/src/precompiles/mod.rs @@ -159,7 +159,6 @@ fn transfer_back_to_caller( account_id: &AccountId32, amount: U256, ) -> Result<(), PrecompileFailure> { - // this is staking smart contract's(0x0000000000000000000000000000000000000801) sr25519 address let smart_contract_account_id = match AccountId32::from_ss58check(smart_contract_address) { // match AccountId32::from_ss58check("5CwnBK9Ack1mhznmCnwiibCNQc174pYQVktYW3ayRpLm4K2X") { Ok(addr) => addr, From 5f22fdac87cf60384e0f6bfe2c00ea9c50e98744 Mon Sep 17 00:00:00 2001 From: open-junius Date: Tue, 17 Dec 2024 10:26:34 +0800 Subject: [PATCH 06/14] fix wrong contract address name --- runtime/src/precompiles/subnet.rs | 48 +++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/runtime/src/precompiles/subnet.rs b/runtime/src/precompiles/subnet.rs index a57103a39..e3a375f73 100644 --- a/runtime/src/precompiles/subnet.rs +++ b/runtime/src/precompiles/subnet.rs @@ -11,7 +11,7 @@ pub const SUBNET_PRECOMPILE_INDEX: u64 = 2051; pub const MAX_PARAMETER_SIZE: usize = 3 * 1024; // this is staking smart contract's(0x0000000000000000000000000000000000000803) sr25519 address -pub const STAKING_CONTRACT_ADDRESS: &str = "5DPSUCb5mZFfizvBDSnRoAqmxV5Bmov2CS3xV773qU6VP1w2"; +pub const SUBNET_CONTRACT_ADDRESS: &str = "5DPSUCb5mZFfizvBDSnRoAqmxV5Bmov2CS3xV773qU6VP1w2"; pub struct SubnetPrecompile; @@ -213,7 +213,7 @@ impl SubnetPrecompile { ) }; - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_serving_rate_limit(data: &[u8]) -> PrecompileResult { @@ -240,7 +240,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_min_difficulty(data: &[u8]) -> PrecompileResult { @@ -267,7 +267,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_max_difficulty(data: &[u8]) -> PrecompileResult { @@ -294,7 +294,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_weights_version_key(data: &[u8]) -> PrecompileResult { @@ -324,7 +324,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_weights_set_rate_limit(data: &[u8]) -> PrecompileResult { @@ -355,7 +355,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_adjustment_alpha(data: &[u8]) -> PrecompileResult { @@ -382,7 +382,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_max_weight_limit(data: &[u8]) -> PrecompileResult { @@ -409,7 +409,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_immunity_period(data: &[u8]) -> PrecompileResult { @@ -436,7 +436,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_min_allowed_weights(data: &[u8]) -> PrecompileResult { @@ -466,7 +466,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_kappa(data: &[u8]) -> PrecompileResult { @@ -491,7 +491,7 @@ impl SubnetPrecompile { kappa, }); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_rho(data: &[u8]) -> PrecompileResult { @@ -516,7 +516,7 @@ impl SubnetPrecompile { rho, }); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_activity_cutoff(data: &[u8]) -> PrecompileResult { @@ -543,7 +543,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_network_registration_allowed(data: &[u8]) -> PrecompileResult { @@ -573,7 +573,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_network_pow_registration_allowed(data: &[u8]) -> PrecompileResult { @@ -603,7 +603,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_min_burn(data: &[u8]) -> PrecompileResult { @@ -629,7 +629,7 @@ impl SubnetPrecompile { min_burn, }); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_max_burn(data: &[u8]) -> PrecompileResult { @@ -655,7 +655,7 @@ impl SubnetPrecompile { max_burn, }); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_difficulty(data: &[u8]) -> PrecompileResult { @@ -681,7 +681,7 @@ impl SubnetPrecompile { difficulty, }); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_bonds_moving_average(data: &[u8]) -> PrecompileResult { @@ -711,7 +711,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_commit_reveal_weights_enabled(data: &[u8]) -> PrecompileResult { @@ -741,7 +741,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_liquid_alpha_enabled(data: &[u8]) -> PrecompileResult { @@ -768,7 +768,7 @@ impl SubnetPrecompile { pallet_admin_utils::Call::::sudo_set_liquid_alpha_enabled { netuid, enabled }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_alpha_values(data: &[u8]) -> PrecompileResult { @@ -798,7 +798,7 @@ impl SubnetPrecompile { alpha_high, }); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn get_commit_reveal_weights_interval(data: &[u8]) -> PrecompileResult { @@ -828,7 +828,7 @@ impl SubnetPrecompile { }, ); - dispatch(handle, call, STAKING_CONTRACT_ADDRESS) + dispatch(handle, call, SUBNET_CONTRACT_ADDRESS) } fn parse_register_network_parameters( From 564b76d2bbc5ae879b7af2bfe99009c596e17dcf Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 31 Jan 2025 14:43:27 +0800 Subject: [PATCH 07/14] refactor code --- runtime/src/precompiles/subnet.rs | 75 ++++++++++++------------------- 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/runtime/src/precompiles/subnet.rs b/runtime/src/precompiles/subnet.rs index 5e5c34a4a..ce6c27e96 100644 --- a/runtime/src/precompiles/subnet.rs +++ b/runtime/src/precompiles/subnet.rs @@ -10,6 +10,8 @@ use sp_core::U256; use sp_runtime::traits::BlakeTwo256; use sp_runtime::AccountId32; use sp_std::vec; + +use super::parse_netuid; pub const SUBNET_PRECOMPILE_INDEX: u64 = 2051; // bytes with max lenght 1K pub const MAX_SINGLE_PARAMETER_SIZE: usize = 1024; @@ -242,7 +244,7 @@ impl SubnetPrecompile { } fn get_serving_rate_limit(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::ServingRateLimit::::get(netuid); @@ -274,7 +276,7 @@ impl SubnetPrecompile { } fn get_min_difficulty(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::MinDifficulty::::get(netuid); @@ -306,7 +308,7 @@ impl SubnetPrecompile { } fn get_max_difficulty(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::MaxDifficulty::::get(netuid); @@ -338,7 +340,7 @@ impl SubnetPrecompile { } fn get_weights_version_key(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::WeightsVersionKey::::get(netuid); @@ -373,7 +375,7 @@ impl SubnetPrecompile { } fn get_weights_set_rate_limit(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::WeightsSetRateLimit::::get(netuid); @@ -409,7 +411,7 @@ impl SubnetPrecompile { } fn get_adjustment_alpha(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::AdjustmentAlpha::::get(netuid); @@ -441,7 +443,7 @@ impl SubnetPrecompile { } fn get_max_weight_limit(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::MaxWeightsLimit::::get(netuid); @@ -473,7 +475,7 @@ impl SubnetPrecompile { } fn get_immunity_period(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::ImmunityPeriod::::get(netuid); @@ -505,7 +507,7 @@ impl SubnetPrecompile { } fn get_min_allowed_weights(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::MinAllowedWeights::::get(netuid); @@ -540,7 +542,7 @@ impl SubnetPrecompile { } fn get_kappa(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::Kappa::::get(netuid); @@ -570,7 +572,7 @@ impl SubnetPrecompile { } fn get_rho(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::Rho::::get(netuid); @@ -600,7 +602,7 @@ impl SubnetPrecompile { } fn get_activity_cutoff(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::ActivityCutoff::::get(netuid); @@ -632,7 +634,7 @@ impl SubnetPrecompile { } fn get_network_registration_allowed(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::NetworkRegistrationAllowed::::get(netuid); @@ -667,7 +669,7 @@ impl SubnetPrecompile { } fn get_network_pow_registration_allowed(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::NetworkPowRegistrationAllowed::::get(netuid); @@ -702,7 +704,7 @@ impl SubnetPrecompile { } fn get_min_burn(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::MinBurn::::get(netuid); @@ -733,7 +735,7 @@ impl SubnetPrecompile { } fn get_max_burn(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::MaxBurn::::get(netuid); @@ -764,7 +766,7 @@ impl SubnetPrecompile { } fn get_difficulty(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::Difficulty::::get(netuid); @@ -795,7 +797,7 @@ impl SubnetPrecompile { } fn get_bonds_moving_average(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::BondsMovingAverage::::get(netuid); @@ -830,7 +832,7 @@ impl SubnetPrecompile { } fn get_commit_reveal_weights_enabled(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::CommitRevealWeightsEnabled::::get(netuid); @@ -865,7 +867,7 @@ impl SubnetPrecompile { } fn get_liquid_alpha_enabled(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::LiquidAlphaOn::::get(netuid); @@ -897,7 +899,7 @@ impl SubnetPrecompile { } fn get_alpha_values(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let (alpha_low, alpha_high) = pallet_subtensor::AlphaValues::::get(netuid); @@ -932,7 +934,7 @@ impl SubnetPrecompile { } fn get_commit_reveal_weights_interval(data: &[u8]) -> PrecompileResult { - let netuid = Self::parse_netuid(data)?; + let netuid = parse_netuid(data, 30)?; let value = pallet_subtensor::RevealPeriodEpochs::::get(netuid); @@ -1083,28 +1085,13 @@ impl SubnetPrecompile { Ok((pubkey, name_vec, repo_vec, contact_vec)) } - fn parse_netuid(data: &[u8]) -> Result { - if data.len() < 32 { - return Err(PrecompileFailure::Error { - exit_status: ExitError::InvalidRange, - }); - } - let mut netuid_vec = [0u8; 2]; - netuid_vec.copy_from_slice(get_slice(data, 30, 32)?); - let netuid = u16::from_be_bytes(netuid_vec); - - Ok(netuid) - } - fn parse_netuid_u64_parameter(data: &[u8]) -> Result<(u16, u64), PrecompileFailure> { if data.len() < 64 { return Err(PrecompileFailure::Error { exit_status: ExitError::InvalidRange, }); } - let mut netuid_vec = [0u8; 2]; - netuid_vec.copy_from_slice(get_slice(data, 30, 32)?); - let netuid = u16::from_be_bytes(netuid_vec); + let netuid = parse_netuid(data, 30)?; let mut parameter_vec = [0u8; 8]; parameter_vec.copy_from_slice(get_slice(data, 56, 64)?); @@ -1119,9 +1106,7 @@ impl SubnetPrecompile { exit_status: ExitError::InvalidRange, }); } - let mut netuid_vec = [0u8; 2]; - netuid_vec.copy_from_slice(get_slice(data, 30, 32)?); - let netuid = u16::from_be_bytes(netuid_vec); + let netuid = parse_netuid(data, 30)?; let mut parameter_vec = [0u8; 2]; parameter_vec.copy_from_slice(get_slice(data, 62, 64)?); @@ -1136,9 +1121,7 @@ impl SubnetPrecompile { exit_status: ExitError::InvalidRange, }); } - let mut netuid_vec = [0u8; 2]; - netuid_vec.copy_from_slice(get_slice(data, 30, 32)?); - let netuid = u16::from_be_bytes(netuid_vec); + let netuid = parse_netuid(data, 30)?; let mut parameter_1_vec = [0u8; 2]; parameter_1_vec.copy_from_slice(get_slice(data, 62, 64)?); @@ -1157,9 +1140,7 @@ impl SubnetPrecompile { exit_status: ExitError::InvalidRange, }); } - let mut netuid_vec = [0u8; 2]; - netuid_vec.copy_from_slice(get_slice(data, 30, 32)?); - let netuid = u16::from_be_bytes(netuid_vec); + let netuid = parse_netuid(data, 30)?; let mut parameter_vec = [0_u8]; parameter_vec.copy_from_slice(get_slice(data, 63, 64)?); From e2c5115510d550790646e4dce9042b9201589ee5 Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 31 Jan 2025 14:57:34 +0800 Subject: [PATCH 08/14] reorg import --- runtime/src/precompiles/subnet.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/src/precompiles/subnet.rs b/runtime/src/precompiles/subnet.rs index ce6c27e96..2d6181639 100644 --- a/runtime/src/precompiles/subnet.rs +++ b/runtime/src/precompiles/subnet.rs @@ -1,4 +1,6 @@ -use crate::precompiles::{get_method_id, get_pubkey, get_slice, try_dispatch_runtime_call}; +use crate::precompiles::{ + get_method_id, get_pubkey, get_slice, parse_netuid, try_dispatch_runtime_call, +}; use crate::{Runtime, RuntimeCall}; use frame_system::RawOrigin; use pallet_evm::{ @@ -7,11 +9,9 @@ use pallet_evm::{ }; use sp_core::U256; -use sp_runtime::traits::BlakeTwo256; -use sp_runtime::AccountId32; +use sp_runtime::{traits::BlakeTwo256, AccountId32}; use sp_std::vec; -use super::parse_netuid; pub const SUBNET_PRECOMPILE_INDEX: u64 = 2051; // bytes with max lenght 1K pub const MAX_SINGLE_PARAMETER_SIZE: usize = 1024; @@ -1116,7 +1116,7 @@ impl SubnetPrecompile { } fn parse_netuid_u16_u16_parameter(data: &[u8]) -> Result<(u16, u16, u16), PrecompileFailure> { - if data.len() < 64 { + if data.len() < 96 { return Err(PrecompileFailure::Error { exit_status: ExitError::InvalidRange, }); From 648cd8194541237e3d9ea8c18e60204d03528735 Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 31 Jan 2025 14:59:29 +0800 Subject: [PATCH 09/14] fix wrong origin --- runtime/src/precompiles/neuron.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/src/precompiles/neuron.rs b/runtime/src/precompiles/neuron.rs index 97167c900..09f86433b 100644 --- a/runtime/src/precompiles/neuron.rs +++ b/runtime/src/precompiles/neuron.rs @@ -44,7 +44,13 @@ impl NeuronPrecompile { netuid, hotkey, }); - try_dispatch_runtime_call(handle, call, contract_to_origin(&CONTRACT_ADDRESS_SS58)?) + + let account_id = + as AddressMapping>::into_account_id( + handle.context().caller, + ); + + try_dispatch_runtime_call(handle, call, RawOrigin::Signed(account_id)) } fn parse_netuid_hotkey_parameter(data: &[u8]) -> Result<(u16, AccountId32), PrecompileFailure> { From 256e7a98103586bf975ab4831e80a123251b7060 Mon Sep 17 00:00:00 2001 From: open-junius Date: Mon, 3 Feb 2025 19:44:56 +0800 Subject: [PATCH 10/14] fix clippy --- Cargo.lock | 10 +++++----- runtime/src/precompiles/neuron.rs | 14 +++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 42522da32..2e66bfd09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1779,7 +1779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1145d32e826a7748b69ee8fc62d3e6355ff7f1051df53141e7048162fc90481b" dependencies = [ "data-encoding", - "syn 2.0.96", + "syn 1.0.109", ] [[package]] @@ -6126,9 +6126,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.69" +version = "0.10.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5e534d133a060a3c19daec1eb3e98ec6f4685978834f2dbadfe2ec215bab64e" +checksum = "61cfb4e166a8bb8c9b55c500bc2308550148ece889be90f609377e58140f42c6" dependencies = [ "bitflags 2.8.0", "cfg-if", @@ -6167,9 +6167,9 @@ dependencies = [ [[package]] name = "openssl-sys" -version = "0.9.104" +version = "0.9.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" +checksum = "8b22d5b84be05a8d6947c7cb71f7c849aa0f112acd4bf51c2a7c1c988ac0a9dc" dependencies = [ "cc", "libc", diff --git a/runtime/src/precompiles/neuron.rs b/runtime/src/precompiles/neuron.rs index 09f86433b..42532582d 100644 --- a/runtime/src/precompiles/neuron.rs +++ b/runtime/src/precompiles/neuron.rs @@ -1,17 +1,21 @@ -use pallet_evm::{ExitError, PrecompileFailure, PrecompileHandle, PrecompileResult}; +use pallet_evm::{ + AddressMapping, ExitError, HashedAddressMapping, PrecompileFailure, PrecompileHandle, + PrecompileResult, +}; use crate::precompiles::{ - contract_to_origin, get_method_id, get_pubkey, get_slice, parse_netuid, - try_dispatch_runtime_call, + get_method_id, get_pubkey, get_slice, parse_netuid, try_dispatch_runtime_call, }; +use crate::RawOrigin; +use crate::{Runtime, RuntimeCall}; +use sp_runtime::traits::BlakeTwo256; use sp_runtime::AccountId32; use sp_std::vec; - -use crate::{Runtime, RuntimeCall}; pub const NEURON_PRECOMPILE_INDEX: u64 = 2052; // ss58 public key i.e., the contract sends funds it received to the destination address from the // method parameter. +#[allow(dead_code)] const CONTRACT_ADDRESS_SS58: [u8; 32] = [ 0xbc, 0x46, 0x35, 0x79, 0xbc, 0x99, 0xf9, 0xee, 0x7c, 0x59, 0xed, 0xee, 0x20, 0x61, 0xa3, 0x09, 0xd2, 0x1e, 0x68, 0xd5, 0x39, 0xb6, 0x40, 0xec, 0x66, 0x46, 0x90, 0x30, 0xab, 0x74, 0xc1, 0xdb, From bf1bcfbe992088c75efdf9583ddcce00dd5667df Mon Sep 17 00:00:00 2001 From: open-junius Date: Tue, 4 Feb 2025 23:44:39 +0800 Subject: [PATCH 11/14] remove duplicated function --- runtime/src/precompiles/solidity/subnet.sol | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/runtime/src/precompiles/solidity/subnet.sol b/runtime/src/precompiles/solidity/subnet.sol index b2d127f11..b6d005706 100644 --- a/runtime/src/precompiles/solidity/subnet.sol +++ b/runtime/src/precompiles/solidity/subnet.sol @@ -165,14 +165,4 @@ interface ISubnet { uint16 netuid, uint64 commitRevealWeightsInterval ) external payable; - - /// Registers a new network without specifying details. - function registerNetwork(bytes32 hotkey) external payable; - /// Registers a new network with specified subnet name, GitHub repository, and contact information. - function registerNetwork( - bytes32 hotkey, - bytes memory subnetName, - bytes memory githubRepo, - bytes memory subnetContact - ) external payable; } From 20b53f5f82e2d33b44100bd1dca0485ef862a381 Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 7 Feb 2025 11:10:25 +0800 Subject: [PATCH 12/14] fix audit --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae335a229..2f60ebd04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3468,9 +3468,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.0" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ "allocator-api2", "equivalent", @@ -3932,7 +3932,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.0", + "hashbrown 0.15.2", ] [[package]] @@ -4923,7 +4923,7 @@ version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "hashbrown 0.15.0", + "hashbrown 0.15.2", ] [[package]] From 1591e882f3fd4e29f03d8cd2ae0d814bacc27fa3 Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 7 Feb 2025 11:35:23 +0800 Subject: [PATCH 13/14] fix audit --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f60ebd04..6c4349b1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5909,9 +5909,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.68" +version = "0.10.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" +checksum = "61cfb4e166a8bb8c9b55c500bc2308550148ece889be90f609377e58140f42c6" dependencies = [ "bitflags 2.6.0", "cfg-if", @@ -5950,9 +5950,9 @@ dependencies = [ [[package]] name = "openssl-sys" -version = "0.9.104" +version = "0.9.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" +checksum = "8b22d5b84be05a8d6947c7cb71f7c849aa0f112acd4bf51c2a7c1c988ac0a9dc" dependencies = [ "cc", "libc", From 8231c0b231bef2076f51677357dec021ea2ef312 Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 7 Feb 2025 16:22:25 +0800 Subject: [PATCH 14/14] fix contract --- runtime/src/precompiles/solidity/subnet.abi | 242 ++++++++++---------- runtime/src/precompiles/solidity/subnet.sol | 3 +- 2 files changed, 118 insertions(+), 127 deletions(-) diff --git a/runtime/src/precompiles/solidity/subnet.abi b/runtime/src/precompiles/solidity/subnet.abi index fc8855f20..fd81850b7 100644 --- a/runtime/src/precompiles/solidity/subnet.abi +++ b/runtime/src/precompiles/solidity/subnet.abi @@ -1,4 +1,23 @@ [ + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getActivityCutoff", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -80,6 +99,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getCommitRevealWeightsInterval", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -137,6 +175,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getLiquidAlphaEnabled", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -251,6 +308,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "netuid", + "type": "uint16" + } + ], + "name": "getNetworkPowRegistrationAllowed", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -348,6 +424,24 @@ }, { "inputs": [ + { + "internalType": "bytes32", + "name": "hotkey", + "type": "bytes32" + } + ], + "name": "registerNetwork", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "hotkey", + "type": "bytes32" + }, { "internalType": "bytes", "name": "subnetName", @@ -362,6 +456,26 @@ "internalType": "bytes", "name": "subnetContact", "type": "bytes" + }, + { + "internalType": "bytes", + "name": "subnetUrl", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "discord", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "description", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "additional", + "type": "bytes" } ], "name": "registerNetwork", @@ -369,13 +483,6 @@ "stateMutability": "payable", "type": "function" }, - { - "inputs": [], - "name": "registerNetwork", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, { "inputs": [ { @@ -394,25 +501,6 @@ "stateMutability": "payable", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint16", - "name": "netuid", - "type": "uint16" - } - ], - "name": "getActivityCutoff", - "outputs": [ - { - "internalType": "uint16", - "name": "", - "type": "uint16" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [ { @@ -490,25 +578,6 @@ "stateMutability": "payable", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint16", - "name": "netuid", - "type": "uint16" - } - ], - "name": "getCommitRevealWeightsInterval", - "outputs": [ - { - "internalType": "uint64", - "name": "", - "type": "uint64" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [ { @@ -581,25 +650,6 @@ "stateMutability": "payable", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint16", - "name": "netuid", - "type": "uint16" - } - ], - "name": "getLiquidAlphaEnabled", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [ { @@ -726,25 +776,6 @@ "stateMutability": "payable", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint16", - "name": "netuid", - "type": "uint16" - } - ], - "name": "getNetworkPowRegistrationAllowed", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [ { @@ -852,46 +883,5 @@ "outputs": [], "stateMutability": "payable", "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "hotkey", - "type": "bytes32" - } - ], - "name": "registerNetwork", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "hotkey", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "subnetName", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "githubRepo", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "subnetContact", - "type": "bytes" - } - ], - "name": "registerNetwork", - "outputs": [], - "stateMutability": "payable", - "type": "function" - } -] + } +] \ No newline at end of file diff --git a/runtime/src/precompiles/solidity/subnet.sol b/runtime/src/precompiles/solidity/subnet.sol index 868132811..1afeced49 100644 --- a/runtime/src/precompiles/solidity/subnet.sol +++ b/runtime/src/precompiles/solidity/subnet.sol @@ -4,9 +4,10 @@ address constant ISUBNET_ADDRESS = 0x0000000000000000000000000000000000000803; interface ISubnet { /// Registers a new network without specifying details. - function registerNetwork() external payable; + function registerNetwork(bytes32 hotkey) external payable; /// Registers a new network with specified subnet name, GitHub repository, and contact information. function registerNetwork( + bytes32 hotkey, bytes memory subnetName, bytes memory githubRepo, bytes memory subnetContact,