Skip to content

Commit

Permalink
Merge branch 'devnet-ready' into feat/rao-devnet-ready
Browse files Browse the repository at this point in the history
  • Loading branch information
gztensor committed Nov 8, 2024
2 parents a3efc24 + 31d801e commit 0d17d0a
Show file tree
Hide file tree
Showing 18 changed files with 2,406 additions and 88 deletions.
10 changes: 5 additions & 5 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ use node_subtensor_runtime::{
/// imported and generated.
const GRANDPA_JUSTIFICATION_PERIOD: u32 = 512;

/// Only enable the benchmarking host functions when we actually want to benchmark.
#[cfg(feature = "runtime-benchmarks")]
/// Always enable runtime benchmark host functions, the genesis state
/// was built with them so we're stuck with them forever.
///
/// They're just a noop, never actually get used if the runtime was not compiled with
/// `runtime-benchmarks`.
pub type HostFunctions = (
sp_io::SubstrateHostFunctions,
frame_benchmarking::benchmarking::HostFunctions,
);
/// Otherwise we use empty host functions for ext host functions.
#[cfg(not(feature = "runtime-benchmarks"))]
pub type HostFunctions = sp_io::SubstrateHostFunctions;

pub type Backend = FullBackend<Block>;
pub type Client = FullClient<Block, RuntimeApi, HostFunctions>;
Expand Down
29 changes: 14 additions & 15 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,7 @@ pub mod pallet {
/// Returns the transaction priority for setting weights.
pub fn get_priority_set_weights(hotkey: &T::AccountId, netuid: u16) -> u64 {
if let Ok(uid) = Self::get_uid_for_net_and_hotkey(netuid, hotkey) {
// TODO rethink this.
let _stake = Self::get_global_for_hotkey(hotkey);
let _stake = Self::get_stake_for_hotkey_on_subnet(hotkey, netuid);
let current_block_number: u64 = Self::get_current_block_as_u64();
let default_priority: u64 =
current_block_number.saturating_sub(Self::get_last_update_for_uid(netuid, uid));
Expand All @@ -1271,18 +1270,7 @@ pub mod pallet {
/// Is the caller allowed to set weights
pub fn check_weights_min_stake(hotkey: &T::AccountId, netuid: u16) -> bool {
// Blacklist weights transactions for low stake peers.
let min_stake = Self::get_weights_min_stake();
let hotkey_stake = Self::get_stake_for_hotkey_on_subnet(hotkey, netuid);
let result = hotkey_stake >= min_stake;
log::info!(
"Checking weights min stake for hotkey: {:?}, netuid: {}, min_stake: {}, hotkey_stake: {}, result: {}",
hotkey,
netuid,
min_stake,
hotkey_stake,
result
);
result
Self::get_stake_for_hotkey_on_subnet(hotkey, netuid) >= Self::get_weights_min_stake()
}

/// Helper function to check if register is allowed
Expand Down Expand Up @@ -1437,6 +1425,18 @@ where
Err(InvalidTransaction::Custom(2).into())
}
}
Some(Call::batch_reveal_weights { netuid, .. }) => {
if Self::check_weights_min_stake(who, *netuid) {
let priority: u64 = Self::get_priority_set_weights(who, *netuid);
Ok(ValidTransaction {
priority,
longevity: 1,
..Default::default()
})
} else {
Err(InvalidTransaction::Custom(6).into())
}
}
Some(Call::set_weights { netuid, .. }) => {
if Self::check_weights_min_stake(who, *netuid) {
let priority: u64 = Self::get_priority_set_weights(who, *netuid);
Expand All @@ -1451,7 +1451,6 @@ where
}
Some(Call::set_root_weights { netuid, hotkey, .. }) => {
if Self::check_weights_min_stake(hotkey, *netuid) {
let priority: u64 = Self::get_priority_set_weights(hotkey, *netuid);
Ok(ValidTransaction {
priority,
longevity: 1,
Expand Down
Loading

0 comments on commit 0d17d0a

Please sign in to comment.