repo_name
stringlengths
1
62
dataset
stringclasses
1 value
lang
stringclasses
11 values
pr_id
int64
1
20.1k
owner
stringlengths
2
34
reviewer
stringlengths
2
39
diff_hunk
stringlengths
15
262k
code_review_comment
stringlengths
1
99.6k
subtensor
github_2023
others
620
opentensor
orriin
@@ -1380,3 +1386,25 @@ fn test_coldkey_has_associated_hotkeys() { )); }); } + +// #[test]
Is this intentionally commented out?
subtensor
github_2023
others
620
opentensor
orriin
@@ -312,26 +312,9 @@ impl Contains<RuntimeCall> for SafeModeWhitelistedCalls { | RuntimeCall::SafeMode(_) | RuntimeCall::Timestamp(_) | RuntimeCall::SubtensorModule( - pallet_subtensor::Call::add_stake { .. }
Are these intentionally removed?
subtensor
github_2023
others
620
opentensor
gztensor
@@ -115,47 +122,287 @@ impl<T: Config> Pallet<T> { old_coldkey: &T::AccountId, new_coldkey: &T::AccountId, ) -> DispatchResultWithPostInfo { - ensure_signed(origin)?; + let coldkey_performing_swap = ensure_signed(origin)?; + ensure!( + !Self::coldkey_in_arbitration...
We should check if `source_coldkeys` length is not zero before performing this `remove` because it adds an unnecessary read on every block otherwise.
subtensor
github_2023
others
620
opentensor
sam0x17
@@ -83,6 +84,9 @@ pub mod pallet { /// order of migrations. (i.e. always increasing) const STORAGE_VERSION: StorageVersion = StorageVersion::new(6); + /// Minimum balance required to perform a coldkey swap + pub const MIN_BALANCE_TO_PERFORM_COLDKEY_SWAP: u64 = 1_000_000_000; // 1 TAO in RAO
I get that this will prevent spam from arbitrary keys, but what will we do if/when someone reaches out to us who has less than 1 TAO but wants to upgrade their key? Just want to make sure we have thought through that edge case. If our plan is to tell them they need 1 TAO to upgrade their key and if they have less they ...
subtensor
github_2023
others
620
opentensor
sam0x17
@@ -112,50 +119,308 @@ impl<T: Config> Pallet<T> { /// Weight is tracked and updated throughout the function execution. pub fn do_swap_coldkey( origin: T::RuntimeOrigin, - old_coldkey: &T::AccountId, new_coldkey: &T::AccountId, ) -> DispatchResultWithPostInfo { - ensure_si...
ideally we should benchmark a single swap and use the resulting weight as our means for estimating the weight of n swaps. I think breaking early makes sense but we have to be certain we aren't underestimating weight, so perhaps we double it
subtensor
github_2023
others
533
opentensor
kianenigma
@@ -0,0 +1,7 @@ +use subtensor_macros::freeze_struct; + +#[freeze_struct("ecdcaac0f6da589a")]
How can one calculate this hash in an easy way?
subtensor
github_2023
others
533
opentensor
keithtensor
@@ -0,0 +1,68 @@ +use proc_macro::TokenStream; +use proc_macro2::TokenStream as TokenStream2; +use quote::ToTokens; +use syn::{parse2, visit_mut::visit_item_struct_mut, Error, ItemStruct, LitStr, Result}; + +mod visitor; +use visitor::*; + +/// Freezes the layout of a struct to the current hash of its fields, ensuring ...
I'm still not seeing how `item_clone` is later used in this function.
subtensor
github_2023
others
533
opentensor
keithtensor
@@ -139,7 +139,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 154,...
Should we just leave this unchanged?
subtensor
github_2023
others
611
opentensor
keithtensor
@@ -35,11 +35,7 @@ clippy-fix: -A clippy::todo \ -A clippy::unimplemented \ -A clippy::indexing_slicing - @echo "Running cargo clippy with automatic fixes on potentially dirty code..." - cargo +{{RUSTV}} clippy --fix --allow-dirty --workspace --all-targets -- \
Why are these checks removed?
subtensor
github_2023
others
611
opentensor
keithtensor
@@ -363,6 +363,9 @@ pub mod pallet { #[pallet::storage] // --- MAP ( hot ) --> cold | Returns the controlling coldkey for a hotkey. pub type Owner<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, T::AccountId, ValueQuery, DefaultAccount<T>>; + #[pallet::storage] // --- MAP ( cold ) --> V...
I would probably call this `OwnedHotkeys` to make the intent clear.
subtensor
github_2023
others
611
opentensor
open-junius
@@ -1204,6 +1207,13 @@ pub mod pallet { // Fill stake information. Owner::<T>::insert(hotkey.clone(), coldkey.clone()); + // Update Owned map + let mut hotkeys = Owned::<T>::get(coldkey);
can put it out of the inner loop, just update Owned once.
subtensor
github_2023
others
611
opentensor
open-junius
@@ -92,6 +92,102 @@ impl<T: Config> Pallet<T> { Ok(Some(weight).into()) } + /// Swaps the coldkey associated with a set of hotkeys from an old coldkey to a new coldkey. + /// + /// # Arguments + /// + /// * `origin` - The origin of the call, which must be signed by the old coldkey. + /...
if caller must be the same as old_coldkey, we don't need this argument in extrinsic.
subtensor
github_2023
others
611
opentensor
open-junius
@@ -92,6 +92,102 @@ impl<T: Config> Pallet<T> { Ok(Some(weight).into()) } + /// Swaps the coldkey associated with a set of hotkeys from an old coldkey to a new coldkey. + /// + /// # Arguments + /// + /// * `origin` - The origin of the call, which must be signed by the old coldkey. + /...
no need to record it. the old coldkey will be removed and not exist anymore.
subtensor
github_2023
others
611
opentensor
orriin
@@ -1325,7 +1335,9 @@ pub mod pallet { // Storage version v4 -> v5 .saturating_add(migration::migrate_delete_subnet_3::<T>()) // Doesn't check storage version. TODO: Remove after upgrade - .saturating_add(migration::migration5_total_issuance::<T>(false))...
Do we know the number of storage read/writes here?
subtensor
github_2023
others
611
opentensor
orriin
@@ -477,3 +477,43 @@ pub fn migrate_to_v2_fixed_total_stake<T: Config>() -> Weight { Weight::zero() } } + +pub fn migrate_populate_owned<T: Config>() -> Weight { + // Setup migration weight + let mut weight = T::DbWeight::get().reads(1); + let migration_name = "Populate Owned map"; + + // Che...
Why is it important to log the longest?
subtensor
github_2023
others
611
opentensor
orriin
@@ -560,6 +560,13 @@ impl<T: Config> Pallet<T> { if !Self::hotkey_account_exists(hotkey) { Stake::<T>::insert(hotkey, coldkey, 0); Owner::<T>::insert(hotkey, coldkey); + + // Update Owned map + let mut hotkeys = Owned::<T>::get(coldkey); + if !hotkeys....
This could be more efficient if `Owned` was a Map -> Set instead of Map -> Vec, maybe it makes more sense?
subtensor
github_2023
others
611
opentensor
orriin
@@ -92,6 +92,102 @@ impl<T: Config> Pallet<T> { Ok(Some(weight).into()) } + /// Swaps the coldkey associated with a set of hotkeys from an old coldkey to a new coldkey. + /// + /// # Arguments + /// + /// * `origin` - The origin of the call, which must be signed by the old coldkey. + /...
What's the purpose of this ratelimit?
subtensor
github_2023
others
611
opentensor
keithtensor
@@ -781,6 +788,31 @@ impl<T: Config> Pallet<T> { Ok(credit) } + pub fn kill_coldkey_account( + coldkey: &T::AccountId, + amount: <<T as Config>::Currency as fungible::Inspect<<T as system::Config>::AccountId>>::Balance, + ) -> Result<u64, DispatchError> { + if amount == 0 { + ...
Are we certain that `withdraw` returns the remaining balance and not the total amount withdrawn here?
subtensor
github_2023
others
611
opentensor
keithtensor
@@ -92,6 +92,102 @@ impl<T: Config> Pallet<T> { Ok(Some(weight).into()) } + /// Swaps the coldkey associated with a set of hotkeys from an old coldkey to a new coldkey. + /// + /// # Arguments + /// + /// * `origin` - The origin of the call, which must be signed by the old coldkey. + /...
Don't exactly need to clone here, since the variables here aren't being used later on.
subtensor
github_2023
others
611
opentensor
orriin
@@ -396,4 +501,187 @@ impl<T: Config> Pallet<T> { weight.saturating_accrue(T::DbWeight::get().writes(2)); // One write for insert and one for remove } } + + /// Swaps the total stake associated with a coldkey from the old coldkey to the new coldkey. + /// + /// # Arguments + /// +...
Todo?
subtensor
github_2023
others
611
opentensor
camfairchild
@@ -1048,3 +1048,296 @@ fn test_swap_total_hotkey_coldkey_stakes_this_interval_weight_update() { assert_eq!(weight, expected_weight); }); } + +#[test] +fn test_do_swap_coldkey_success() { + new_test_ext(1).execute_with(|| { + let old_coldkey = U256::from(1); + let new_coldkey = U256::fro...
```suggestion assert!(!OwnedHotkeys::<Test>::get(new_coldkey).contains(hotkey)); ``` Might be good to allow moving to a coldkey that may already have other hotkeys.
subtensor
github_2023
others
611
opentensor
camfairchild
@@ -1048,3 +1048,296 @@ fn test_swap_total_hotkey_coldkey_stakes_this_interval_weight_update() { assert_eq!(weight, expected_weight); }); } + +#[test] +fn test_do_swap_coldkey_success() { + new_test_ext(1).execute_with(|| { + let old_coldkey = U256::from(1); + let new_coldkey = U256::fro...
```suggestion let balance_new_coldkey = SubtensorModule::get_coldkey_balance(&new_coldkey); ``` Should track the other coldkey as well
subtensor
github_2023
others
611
opentensor
camfairchild
@@ -1048,3 +1048,296 @@ fn test_swap_total_hotkey_coldkey_stakes_this_interval_weight_update() { assert_eq!(weight, expected_weight); }); } + +#[test] +fn test_do_swap_coldkey_success() { + new_test_ext(1).execute_with(|| { + let old_coldkey = U256::from(1); + let new_coldkey = U256::fro...
```suggestion assert_eq!(SubtensorModule::get_coldkey_balance(&new_coldkey), balance + balance_new_coldkey); ``` Goes with earlier comment
subtensor
github_2023
others
611
opentensor
camfairchild
@@ -1048,3 +1048,296 @@ fn test_swap_total_hotkey_coldkey_stakes_this_interval_weight_update() { assert_eq!(weight, expected_weight); }); } + +#[test] +fn test_do_swap_coldkey_success() { + new_test_ext(1).execute_with(|| { + let old_coldkey = U256::from(1); + let new_coldkey = U256::fro...
Should test further with new_coldkey having existing hotkeys, stake, and balance. Making sure not to overwrite any entries for the new coldkey.
subtensor
github_2023
others
611
opentensor
camfairchild
@@ -1048,3 +1048,296 @@ fn test_swap_total_hotkey_coldkey_stakes_this_interval_weight_update() { assert_eq!(weight, expected_weight); }); } + +#[test] +fn test_do_swap_coldkey_success() { + new_test_ext(1).execute_with(|| { + let old_coldkey = U256::from(1); + let new_coldkey = U256::fro...
```suggestion assert_eq!(TotalHotkeyStake::<Test>::get(hotkey1), stake_amount1); assert_eq!(TotalHotkeyStake::<Test>::get(hotkey2), stake_amount2); assert_eq!(TotalStake::<Test>::get(), stake_amount1 + stake_amount2); assert_eq!(TotalIssuance::<Test>::get(), stake_amount1 + stake_amount2); ``` Would be good to ch...
subtensor
github_2023
others
611
opentensor
camfairchild
@@ -92,6 +82,81 @@ impl<T: Config> Pallet<T> { Ok(Some(weight).into()) } + /// Swaps the coldkey associated with a set of hotkeys from an old coldkey to a new coldkey. + /// + /// # Arguments + /// + /// * `origin` - The origin of the call, which must be signed by the old coldkey. + //...
Not sure we shouldn't allow this.
subtensor
github_2023
others
611
opentensor
camfairchild
@@ -92,6 +82,81 @@ impl<T: Config> Pallet<T> { Ok(Some(weight).into()) } + /// Swaps the coldkey associated with a set of hotkeys from an old coldkey to a new coldkey. + /// + /// # Arguments + /// + /// * `origin` - The origin of the call, which must be signed by the old coldkey. + //...
Maybe add comment about order of these swaps being important
subtensor
github_2023
others
556
opentensor
sam0x17
@@ -36,7 +36,7 @@ fn test_registration_subscribe_ok_dispatch_info_ok() { assert_eq!( call.get_dispatch_info(), DispatchInfo { - weight: frame_support::weights::Weight::from_parts(192_000_000, 0), + weight: frame_support::weights::Weight::from_parts(2_992_...
that's quite a big weight change, just flagging but probably fine
subtensor
github_2023
others
556
opentensor
open-junius
@@ -0,0 +1,417 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
can put it out of loop, just execute once.
subtensor
github_2023
others
556
opentensor
JohnReedV
@@ -262,6 +266,11 @@ pub mod pallet { pub fn TotalSupply<T: Config>() -> u64 { 21_000_000_000_000_000 // Rao => 21_000_000 Tao } + /// Hotkey swap cost. + #[pallet::type_value] + pub fn HotkeySwapCost<T: Config>() -> u64 {
Not sure this is actually being used? Seems like it is using `InitialHotkeySwapCost` as the default instead.
subtensor
github_2023
others
553
opentensor
sam0x17
@@ -284,6 +284,49 @@ impl pallet_utility::Config for Runtime { type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>; } +parameter_types! { + pub const DisallowPermissionlessEnterDuration: BlockNumber = 0; + pub const DisallowPermissionlessExtendDuration: BlockNumber = 0; + + pub const Ro...
just wanted to double check we don't want to whitelist any other calls, and that we can perform a runtime upgrade when in safemode as that seems a likely safemode activity
subtensor
github_2023
others
571
opentensor
distributedstatemachine
@@ -174,31 +174,31 @@ You can now run the public subtensor node either as a lite node or as an archive To run a lite node connected to the mainchain, execute the below command (note the `--sync=warp` flag which runs the subtensor node in lite mode): ```bash title="With --sync=warp setting, for lite node" -./target/...
WE need to be careful with the merge , as this is `./target/production/node-subtensor` in the archive node fix branch
subtensor
github_2023
others
552
opentensor
sam0x17
@@ -0,0 +1,2344 @@ +use substrate_fixed::types::{I32F32, I64F64}; + +use pallet_subtensor::math::*; +use rand::{seq::SliceRandom, thread_rng, Rng}; +use substrate_fixed::{ + transcendental::exp, + types::{I110F18, I96F32}, +}; + +fn assert_float_compare(a: I32F32, b: I32F32, epsilon: I32F32) { + assert!(I32F32...
maybe also check that `vecdiv`'s behavior with division by zero is correct, like: ```suggestion #[test] fn test_math_vecdiv_zero_division() { let x: Vec<I32F32> = vec_to_fixed(&[1., 2., 3.]); let y: Vec<I32F32> = vec_to_fixed(&[0., 0., 0.]); let result = vecdiv(&x, &y); assert!(result.iter()....
subtensor
github_2023
others
552
opentensor
sam0x17
@@ -0,0 +1,2344 @@ +use substrate_fixed::types::{I32F32, I64F64}; + +use pallet_subtensor::math::*; +use rand::{seq::SliceRandom, thread_rng, Rng}; +use substrate_fixed::{ + transcendental::exp, + types::{I110F18, I96F32}, +}; + +fn assert_float_compare(a: I32F32, b: I32F32, epsilon: I32F32) { + assert!(I32F32...
Perhaps a check that `normalize` handles cases where the input vector sum is zero to avoid division by zero? ```suggestion #[test] fn test_math_normalize_zero_sum() { let epsilon: I32F32 = I32F32::from_num(0.0001); let x: Vec<I32F32> = vec![I32F32::from_num(0.0), I32F32::from_num(0.0)]; let y: Vec...
subtensor
github_2023
others
552
opentensor
sam0x17
@@ -0,0 +1,2344 @@ +use substrate_fixed::types::{I32F32, I64F64}; + +use pallet_subtensor::math::*; +use rand::{seq::SliceRandom, thread_rng, Rng}; +use substrate_fixed::{ + transcendental::exp, + types::{I110F18, I96F32}, +}; + +fn assert_float_compare(a: I32F32, b: I32F32, epsilon: I32F32) { + assert!(I32F32...
maybe test handling when we are over the `u16` capacity? does it saturate?
subtensor
github_2023
others
552
opentensor
sam0x17
@@ -0,0 +1,2344 @@ +use substrate_fixed::types::{I32F32, I64F64}; + +use pallet_subtensor::math::*; +use rand::{seq::SliceRandom, thread_rng, Rng}; +use substrate_fixed::{ + transcendental::exp, + types::{I110F18, I96F32}, +}; + +fn assert_float_compare(a: I32F32, b: I32F32, epsilon: I32F32) { + assert!(I32F32...
Also would be nice to check that `normalize` is handling single and empty inputs correctly: ```suggestion #[test] fn test_empty_and_single_element_cases() { let empty_vec: Vec<I32F32> = vec![]; assert_eq!(normalize(&empty_vec), empty_vec); let single_element_vec: Vec<I32F32> = vec![I32F32::from_...
subtensor
github_2023
others
552
opentensor
Mananitade
@@ -1225,39 +1228,37 @@ fn test_sudo_get_set_alpha() { let hotkey: U256 = U256::from(1); let coldkey: U256 = U256::from(1 + 456); - let signer = <<Test as Config>::RuntimeOrigin>::signed(coldkey.clone()); + let signer = <<Test as Config>::RuntimeOrigin>::signed(coldkey); // ...
This is the line that I'm referring to @distributedstatemachine
subtensor
github_2023
others
552
opentensor
open-junius
@@ -996,6 +996,45 @@ pub mod pallet { log::info!("ToggleSetWeightsCommitReveal( netuid: {:?} ) ", netuid); Ok(()) } + + /// Enables or disables Liquid Alpha for a given subnet. + /// + /// # Parameters + /// - `origin`: The origin of the call, which must be...
It is better to split into two extrinsics, which will make the bittensor easier to implement the command with unified format.
subtensor
github_2023
others
493
opentensor
birkskyum
@@ -60,5 +60,4 @@ FROM $BASE_IMAGE AS subtensor COPY --from=builder /subtensor/snapshot.json / COPY --from=builder /subtensor/raw_spec.json /
isn't raw_spec removed as well?
subtensor
github_2023
others
485
opentensor
orriin
@@ -983,7 +988,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> { Voting::<T, I>::remove(proposal_hash); let num_proposals = Proposals::<T, I>::mutate(|proposals| { proposals.retain(|h| h != &proposal_hash); - proposals.len() + 1 // calculate weight based on original length + ...
```suggestion proposals.len().saturating_inc() // calculate weight based on original length ```
subtensor
github_2023
others
485
opentensor
orriin
@@ -27,9 +28,10 @@ impl<T: Config> Pallet<T> { Ok(()) } - // Helper function which returns the number of blocks remaining before we will run the epoch on this - // network. Networks run their epoch when (block_number + netuid + 1 ) % (tempo + 1) = 0 - // + #[allow(clippy::arithmetic_side_eff...
Why allowed?
subtensor
github_2023
others
485
opentensor
camfairchild
@@ -646,7 +650,11 @@ impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp { r_yes_votes, r_count, )), // Equivalent to (l_yes_votes / l_count).cmp(&(r_yes_votes / r_count)) - ) => Some((l_yes_votes * r_count).cmp(&(r_yes_votes * l_count))), + ...
```suggestion .cmp(&r_yes_votes.saturating_mul(l_count)), ``` Should not be a dereference, I believe
subtensor
github_2023
others
485
opentensor
orriin
@@ -1147,15 +1147,21 @@ pub mod pallet { Stake::<T>::insert(hotkey.clone(), coldkey.clone(), stake); - next_uid += 1; + next_uid = next_uid.checked_add(1).expect( + "should not have total number of hotkey accounts larger than u16::MAX...
u16::MAX is only 65535. is this enough? I think we're close to that, if not already exceeded it?
subtensor
github_2023
others
485
opentensor
orriin
@@ -1147,15 +1147,21 @@ pub mod pallet { Stake::<T>::insert(hotkey.clone(), coldkey.clone(), stake); - next_uid += 1; + next_uid = next_uid.checked_add(1).expect( + "should not have total number of hotkey accounts larger than u16::MAX...
```suggestion "genesis state should not have a total number of hotkey accounts larger than u16::MAX", ```
subtensor
github_2023
others
485
opentensor
distributedstatemachine
@@ -343,7 +343,7 @@ impl<T: Config> Pallet<T> { Self::set_stakes_this_interval_for_coldkey_hotkey( &coldkey, &hotkey, - stakes_this_interval + 1, + stakes_this_interval.saturating_add(1),
inconsistencies between using `saturating_inc` and `saturating_add` for increments of 1
subtensor
github_2023
others
485
opentensor
distributedstatemachine
@@ -456,7 +456,7 @@ impl<T: Config> Pallet<T> { Self::set_stakes_this_interval_for_coldkey_hotkey( &coldkey, &hotkey, - unstakes_this_interval + 1, + unstakes_this_interval.saturating_add(1),
same as above
subtensor
github_2023
others
485
opentensor
distributedstatemachine
@@ -60,7 +60,7 @@ impl<T: Config> Pallet<T> { ); // 2. Get and increase the uid count. - SubnetworkN::<T>::insert(netuid, next_uid + 1); + SubnetworkN::<T>::insert(netuid, next_uid.saturating_add(1));
saturating_add v inc
subtensor
github_2023
others
565
opentensor
distributedstatemachine
@@ -1,49 +1,47 @@ #!/usr/bin/env bash - -DEFAULT_BIN_PATH='./target/release/node-subtensor' +DEFAULT_BIN_PATH='./target/production/node-subtensor' BIN_PATH=$DEFAULT_BIN_PATH TMP_SPEC='temp.json' OUTPUT_FILE='benchmarking.txt' - # Getting arguments from user while [[ $# -gt 0 ]]; do case $1 in - -p|--bin...
`--execution=native` can we take it out since its currently a noop and would soon be deprecated
subtensor
github_2023
others
280
opentensor
distributedstatemachine
@@ -82,6 +84,43 @@ impl<T: Config> Pallet<T> { LoadedEmission::<T>::get(netuid).unwrap() } + // Determines if due for a halving at the current block and + // updates block emissions if so. + // + pub fn check_halving() { + let total_issuance = Self::get_total_issuance(); + let ...
Since the halving occurs every 10_500_000 TAOs , do you think we can avoid the matches and do this instead? ``` pub fn check_halving() { let total_issuance = Self::get_total_issuance(); let current_emission = Self::get_block_emission(); let last_halving_issuance = Self::get_last_halving_issuance(); ...
subtensor
github_2023
others
280
opentensor
sam0x17
@@ -598,4 +599,40 @@ impl<T: Config> Pallet<T> { pub fn is_subnet_owner(address: &T::AccountId) -> bool { SubnetOwner::<T>::iter_values().any(|owner| *address == owner) } + + pub fn log2(x: f64) -> f64 { + let mut y = x; + let mut result = 0.0; + while y < 1.0 { + y...
so I should have thought about this before I helped you get f64 stuff working, but probably a bad idea to have anything on-chain rely on an f64 calculation I would recommend instead using the `rust_decimal` crate with default features disabled, which disables the `std` feature allowing for `no_std` support which wil...
subtensor
github_2023
others
280
opentensor
sam0x17
@@ -82,6 +84,38 @@ impl<T: Config> Pallet<T> { LoadedEmission::<T>::get(netuid).unwrap() } + // Checks the current block emission and + // updates the block emission if the recalculated value is lower + // + pub fn check_halving() { + const ORIGINAL_EMISSION: f64 = 1_000_000_000.0; //...
yeah really really really don't want f64 stuff on chain, sorry again I didn't flag that sooner
subtensor
github_2023
others
280
opentensor
keithtensor
@@ -82,6 +84,38 @@ impl<T: Config> Pallet<T> { LoadedEmission::<T>::get(netuid).unwrap() } + // Checks the current block emission and + // updates the block emission if the recalculated value is lower + //
```suggestion /// Checks the current block emission and /// updates the block emission if the recalculated value is lower ```
subtensor
github_2023
others
280
opentensor
keithtensor
@@ -82,6 +84,38 @@ impl<T: Config> Pallet<T> { LoadedEmission::<T>::get(netuid).unwrap() } + // Checks the current block emission and + // updates the block emission if the recalculated value is lower + // + pub fn check_halving() { + const ORIGINAL_EMISSION: f64 = 1_000_000_000.0; //...
I'm surprised that this isn't already defined somewhere. In fact, it might not be a good idea to define it here, and instead should be a config item where the runtime gets to define what the original emission is. We'd then be able to reuse it here via `T::ORIGINAL_EMISSION`.
subtensor
github_2023
others
280
opentensor
keithtensor
@@ -82,6 +84,38 @@ impl<T: Config> Pallet<T> { LoadedEmission::<T>::get(netuid).unwrap() } + // Checks the current block emission and + // updates the block emission if the recalculated value is lower + // + pub fn check_halving() { + const ORIGINAL_EMISSION: f64 = 1_000_000_000.0; //...
```suggestion /// Calculates the emission rate based on the total issuance, /// where the emission decreases as the total issuance approaches the supply cap. ```
subtensor
github_2023
others
280
opentensor
keithtensor
@@ -82,6 +84,38 @@ impl<T: Config> Pallet<T> { LoadedEmission::<T>::get(netuid).unwrap() } + // Checks the current block emission and + // updates the block emission if the recalculated value is lower + // + pub fn check_halving() { + const ORIGINAL_EMISSION: f64 = 1_000_000_000.0; //...
Same comment as `ORIGINAL_EMISSION` -- define this as a config item, and have the runtime supply this number.
subtensor
github_2023
others
282
opentensor
open-junius
@@ -474,10 +474,11 @@ impl pallet_sudo::Config for Runtime { } parameter_types! { - // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. - pub const DepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (88 as Balance) * 100 * 10_000; + // One storage item; key size is 32 + siz...
value size is 4 + 4 block number + 8 balance + 32 account id = 48
subtensor
github_2023
others
357
opentensor
shibshib
@@ -268,7 +268,7 @@ impl pallet_utility::Config for Runtime { } // Existential deposit. -pub const EXISTENTIAL_DEPOSIT: u64 = 500; +pub const EXISTENTIAL_DEPOSIT: u64 = 2_000_000;
Do we know the implications of this change? If ED is increased, would this affect wallets that have staked tao in their hotkey but 0 tao in their coldkey? It would be problematic for users if all of their tao is staked and then suddenly their cold wallet is destroyed, orphaning their hot wallet. I suppose it's alwa...
subtensor
github_2023
others
355
opentensor
keithtensor
@@ -181,10 +174,12 @@ impl<T: Config> Pallet<T> { Self::increase_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, stake_to_be_added);
How come this is `stake_to_be_added` and not `actual_amount_to_stake`? In step 8, it should have returned this value. This is part of the switch to the `fungible` traits from `Currency` -- why has this change been reverted?
subtensor
github_2023
others
380
opentensor
orriin
@@ -123,10 +123,11 @@ parameter_types! { pub const InitialBondsMovingAverage: u64 = 900_000; pub const InitialStakePruningMin: u16 = 0; pub const InitialFoundationDistribution: u64 = 0; - pub const InitialDefaultTake: u16 = 11_796; // 18% honest number. + pub const InitialDefaultTake: u16 = 32_767;...
why use a different number in tests and runtime?
subtensor
github_2023
others
380
opentensor
orriin
@@ -95,6 +92,150 @@ impl<T: Config> Pallet<T> { Ok(()) } + // ---- The implementation for the extrinsic decrease_take + // + // # Args: + // * 'origin': (<T as frame_system::Config>::RuntimeOrigin): + // - The signature of the caller's coldkey. + // + // * 'hotkey' (T::AccountId...
If these both just set the `take` value, is there a reason they shouldn't be combined into a single extrinsic?
subtensor
github_2023
others
380
opentensor
orriin
@@ -95,6 +92,150 @@ impl<T: Config> Pallet<T> { Ok(()) } + // ---- The implementation for the extrinsic decrease_take + // + // # Args: + // * 'origin': (<T as frame_system::Config>::RuntimeOrigin): + // - The signature of the caller's coldkey. + // + // * 'hotkey' (T::AccountId...
Why not do these checks when decreasing take?
subtensor
github_2023
others
380
opentensor
orriin
@@ -88,7 +88,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::sudo_set_default_take())] pub fn sudo_set_default_take(origin: OriginFor<T>, default_take: u16) -> DispatchResult {
Should this be renamed to reflect the changed functionality? ```suggestion pub fn sudo_set_max_delegate_take(origin: OriginFor<T>, max_take: u16) -> DispatchResult { ```
subtensor
github_2023
others
361
opentensor
shibshib
@@ -765,6 +764,27 @@ pub mod pallet { T::Subtensor::set_weights_min_stake(min_stake); Ok(()) } + + /// Sets the minimum stake required for nominators, and clears small nominations + /// that are below the minimum required stake. + #[pallet::call_index(43)] + ...
Do we always want to increase the min required stake? What if we messed something up and want to reduce it?
subtensor
github_2023
others
361
opentensor
shibshib
@@ -22,30 +23,37 @@ pub mod deprecated_loaded_emission_format { StorageMap<Pallet<T>, Identity, u16, Vec<(AccountIdOf<T>, u64)>, OptionQuery>; } - /// Performs migration to update the total issuance based on the sum of stakes and total balances. /// This migration is applicable only if the current storage...
Do we want a panic during a migration? We should avoid these as much as possible in the critical path.
subtensor
github_2023
others
361
opentensor
shibshib
@@ -158,12 +158,25 @@ impl<T: Config> Pallet<T> { ); // --- 6. Ensure we don't exceed stake rate limit - let stakes_this_interval = Self::get_stakes_this_interval_for_coldkey_hotkey(&coldkey, &hotkey); + let stakes_this_interval = + Self::get_stakes_this_interval_for_coldkey...
can we perhaps add some more documentation as to why we're ensuring that coldkey does NOT own the hotkey?
subtensor
github_2023
others
464
opentensor
camfairchild
@@ -436,26 +436,18 @@ impl<T: Config> Pallet<T> { Error::<T>::UnstakeRateLimitExceeded ); - // If this is a nomination stake, check if total stake after removing will be above - // the minimum required stake. - - // If coldkey is not owner of the hotkey, it's a nomination st...
```suggestion // This only applies to nominator stakes. ```
subtensor
github_2023
others
464
opentensor
keithtensor
@@ -141,7 +141,7 @@ parameter_types! { pub const InitialAdjustmentInterval: u16 = 100; pub const InitialAdjustmentAlpha: u64 = 0; // no weight to previous value. pub const InitialMaxRegistrationsPerBlock: u16 = 3; - pub const InitialTargetRegistrationsPerInterval: u16 = 2; + pub const InitialTarget...
what's this about?
subtensor
github_2023
others
451
opentensor
open-junius
@@ -1423,12 +1423,12 @@ fn test_full_with_delegating() { assert_ok!(SubtensorModule::do_become_delegate( <<Test as Config>::RuntimeOrigin>::signed(coldkey0), hotkey0, - 10 + u16::MAX / 10 )); assert_ok!(SubtensorModule::do_become_delegate( ...
define a const like VALID_TAKE = u16::MAX / 10. then we can use it everywhere. and much easier to update in the future.
subtensor
github_2023
others
451
opentensor
open-junius
@@ -1505,21 +1505,21 @@ fn test_full_with_delegating() { SubtensorModule::emit_inflation_through_hotkey_account(&hotkey1, 0, 1000); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), - 601 - ); // 200 + 1000 x ( 200 / 500 ) = 200 + 400 = ...
pls define a function to calculate it. From function name, parameter name. we can understand what's the formula
subtensor
github_2023
others
451
opentensor
gztensor
@@ -1505,21 +1505,21 @@ fn test_full_with_delegating() { SubtensorModule::emit_inflation_through_hotkey_account(&hotkey1, 0, 1000); assert_eq!( SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0, &hotkey0), - 601 - ); // 200 + 1000 x ( 200 / 500 ) = 200 + 400 = ...
The 650 number is correct, but the formula for nominator's cold key is: ``` validator_take = take * validator_emission = 10% * 1000 = 100 old_stake + (validator_emission - validator_take) * stake_for_coldkey_and_hotkey / total_stake_for_hotkey = 200 + 900 * 200 / 400 = 650 ```
subtensor
github_2023
others
474
opentensor
keithtensor
@@ -803,3 +803,94 @@ fn test_burn_adjustment_case_e_zero_registrations() { assert_eq!(adjusted_diff, 5_000); }); } + +#[test] +fn test_emission_based_on_registration_status() { + new_test_ext(1).execute_with(|| { + let n: u16 = 100; + let netuid_off: u16 = 1; + let netuid_on: u16 ...
This is casting a function pointer to a `u64`, did you really mean to call `next_block()` here?
subtensor
github_2023
others
550
opentensor
keithtensor
@@ -0,0 +1,68 @@ +use proc_macro::TokenStream; +use proc_macro2::TokenStream as TokenStream2; +use quote::ToTokens; +use syn::{parse2, visit_mut::visit_item_struct_mut, Error, ItemStruct, LitStr, Result}; + +mod visitor; +use visitor::*; + +/// Freezes the layout of a struct to the current hash of its fields, ensuring ...
What's the purpose of the `item_clone` variable? It doesn't seem to have served any purpose other than to have been visited by this visitor.
subtensor
github_2023
others
542
opentensor
keithtensor
@@ -0,0 +1,443 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction.
```suggestion /// * `origin` - The origin of the transaction, and also the coldkey account. ```
subtensor
github_2023
others
542
opentensor
keithtensor
@@ -0,0 +1,443 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction. + /// * `old_hotkey`...
This test should probably be checked first before anything, otherwise you'd be wasting computation.
subtensor
github_2023
others
542
opentensor
keithtensor
@@ -0,0 +1,443 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction. + /// * `old_hotkey`...
Can we use `CENTS` or some constant here? This number looks magical without any context.
subtensor
github_2023
others
542
opentensor
gztensor
@@ -0,0 +1,445 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
Why do we need to swap LstTxBlock if we're setting a new value of it at the end of this extrinsic anyway?
subtensor
github_2023
others
542
opentensor
gztensor
@@ -0,0 +1,445 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
Removing prefix may be more efficient
subtensor
github_2023
others
542
opentensor
gztensor
@@ -0,0 +1,1154 @@ +use codec::Encode; +use frame_support::weights::Weight; +use frame_support::{assert_err, assert_ok}; +use frame_system::Config; +mod mock; +use mock::*; +use pallet_subtensor::*; +use sp_core::U256; + +#[test] +fn test_do_swap_hotkey_ok() { + new_test_ext(1).execute_with(|| { + let netuid:...
Do we need a validation for swapping Keys map too?
subtensor
github_2023
others
542
opentensor
orriin
@@ -0,0 +1,422 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
to not spam logs, most of our info logs should be changed to debug ```suggestion log::debug!("Swap cost: {:?}", swap_cost); ```
subtensor
github_2023
others
542
opentensor
orriin
@@ -0,0 +1,422 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
These methods are a noop if the old_hotkey doesn't exist, so unless that's sometimes expected, this should prob return an error in that case in case of silently nooping. Could also add some debug logs in case we need to introspect behavior.
subtensor
github_2023
others
542
opentensor
orriin
@@ -0,0 +1,422 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
Have we checked how many keys will be touched here? Could be a very expensive operation
subtensor
github_2023
others
542
opentensor
keithtensor
@@ -0,0 +1,422 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
How could this function throw an error? Wouldn't it make more sense to just change the return value to `Vec<u16>`?
subtensor
github_2023
others
542
opentensor
keithtensor
@@ -0,0 +1,422 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
Same here: this function couldn't actually throw an error.
subtensor
github_2023
others
542
opentensor
keithtensor
@@ -0,0 +1,422 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
Missing weight calculation from `try_get`, and doesn't really need to return a `DispatchResult`.
subtensor
github_2023
others
542
opentensor
keithtensor
@@ -0,0 +1,422 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
Missing weight calculation for `try_get`.
subtensor
github_2023
others
542
opentensor
keithtensor
@@ -0,0 +1,422 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
Maybe better to just accept a `&[u16]` instead of a `Vec`.
subtensor
github_2023
others
542
opentensor
keithtensor
@@ -0,0 +1,422 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
There's still quite a lot of functions in this file that didn't account for the read in `try_get`.
subtensor
github_2023
others
542
opentensor
keithtensor
@@ -0,0 +1,417 @@ +use super::*; +use frame_support::{storage::IterableStorageDoubleMap, weights::Weight}; +use sp_core::Get; + +impl<T: Config> Pallet<T> { + /// Swaps the hotkey of a coldkey account. + /// + /// # Arguments + /// + /// * `origin` - The origin of the transaction, and also the coldkey ac...
Comment here needs to be updated.
subtensor
github_2023
others
503
opentensor
keithtensor
@@ -1223,3 +1223,21 @@ pub fn mat_ema_alpha_vec( } result } + +/// Return the quantile of a vector of I32F32 values. +pub fn quantile(data: &Vec<I32F32>, quantile: f64) -> I32F32 { + let mut sorted_data = data.clone(); + sorted_data.sort_by(|a, b| a.partial_cmp(b).unwrap());
Can we do `cmp` instead of `partial_cmp` here? The `unwrap` can panic.
subtensor
github_2023
others
527
opentensor
camfairchild
@@ -869,7 +869,9 @@ fn test_emission_based_on_registration_status() { n as usize ); + let block: u64 = 0; // drain the emission tuples for the subnet with registration on + #[allow(clippy::fn_to_numeric_cast)] SubtensorModule::drain_emission(next_block as u64);
```suggestion SubtensorModule::drain_emission(block as u64); ```
subtensor
github_2023
others
527
opentensor
camfairchild
@@ -869,7 +869,9 @@ fn test_emission_based_on_registration_status() { n as usize ); + let block: u64 = 0; // drain the emission tuples for the subnet with registration on + #[allow(clippy::fn_to_numeric_cast)]
```suggestion ```
subtensor
github_2023
others
499
opentensor
sam0x17
@@ -2,12 +2,19 @@ name: Publish Docker Image on: push: - branches: - - main
though I would say if this job produces a docker image, you probably specifically want it on pushes to `main` as well
subtensor
github_2023
others
473
opentensor
distributedstatemachine
@@ -4,6 +4,13 @@ use sp_std::vec::Vec; use substrate_fixed::types::I110F18; use substrate_fixed::types::I64F64; +struct SubnetInfo {
I wonder if we could make the code DRY by reusing the `SubnetInfo` struct from `subnet_info.rs`.
subtensor
github_2023
others
473
opentensor
distributedstatemachine
@@ -138,111 +145,142 @@ impl<T: Config> Pallet<T> { tempo as u64 - (block_number + netuid as u64 + 1) % (tempo as u64 + 1) } - pub fn run_coinbase(block_number: u64) { + fn get_subnets() -> Vec<SubnetInfo> { // Get all the network uids. - let netuids: Vec<u16> = Self::get_all_subne...
Although this wont panic , I think we are moving away from unwraps in general
subtensor
github_2023
others
496
opentensor
sam0x17
@@ -0,0 +1,44 @@ +name: Publish Docker Image + +on: + push: + branches: + - main + tags: + - '*' + workflow_dispatch: + +jobs: + publish: + runs-on: ubuntu-latest
```suggestion runs-on: SubtensorCI ```
subtensor
github_2023
others
479
opentensor
distributedstatemachine
@@ -8,7 +8,7 @@ BASE_DIR="$SCRIPT_DIR/.." : "${CHAIN:=local}" : "${BUILD_BINARY:=1}" -: "${FEATURES:=pow-faucet}" +: "${FEATURES:="pow-faucet runtime-benchmarks"}"
Do we need the `runtime-benchmarks` for localnet ?
subtensor
github_2023
others
346
opentensor
distributedstatemachine
@@ -0,0 +1,25 @@ +name: Label Triggers +on: + pull_request: + types: + - labeled + +permissions: + issues: write + pull-requests: write + +jobs: + comment_on_breaking_change: + runs-on: ubuntu-latest + steps: + - name: Check if 'breaking change' label is added + if: github.event.label.name...
Have we resolved permissioning issues with these alerts?
subtensor
github_2023
others
346
opentensor
distributedstatemachine
@@ -0,0 +1,205 @@ +# Subtensor Contributor Guide + +## Lifecycle of a Pull Request + +1. Individuals wishing to contribute to subtensor should develop their change/feature/fix in a + [Pull Request](https://github.com/opentensor/subtensor/compare) (PR) targeting the `main` + branch of the subtensor GitHub repository...
is this still valid? given the new release cycle (wednesday - wednesday), I think period lasts at least a week
subtensor
github_2023
others
346
opentensor
distributedstatemachine
@@ -0,0 +1,18 @@ +name: Tested on Testnet +on: + pull_request: + types: [opened, labeled, unlabeled, synchronize]
what does `synchronise` do ?
subtensor
github_2023
others
433
opentensor
rajkaramchedu
@@ -66,10 +66,10 @@ pub mod pallet { pub enum Error<T> { /// The subnet does not exist, check the netuid parameter SubnetDoesNotExist, - /// The max allowed validator number to be set is larger than threshold - StorageValueOutOfRange, - /// The maximum allowed UIDs is out of ...
The user mostly knows the subnet hyperparameter "max_validators" https://docs.bittensor.com/subnets/subnet-hyperparameters#max_validators Is "max allowed UIDs" in this context the same as the "max_validators" hyperparameter? Iff so, it might be helpful to include "(the subnet hyperparameter "max_validators")" after "ma...