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 | 599 | opentensor | orriin | @@ -424,8 +426,13 @@ reveal_weights {
weight_values.clone(),
salt.clone(),
version_key,
- ));
- let _ = Subtensor::<T>::commit_weights(<T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), netuid, commit_hash);
+ ));
+ let _ = Subtensor::<T>::commit_weights(... | In benchmark better to not silently fail
```suggestion
Subtensor::<T>::commit_weights(
<T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())),
netuid,
commit_hash,
nonce
).unwrap();
``` |
subtensor | github_2023 | others | 599 | opentensor | orriin | @@ -126,5 +126,11 @@ mod errors {
CommitRevealEnabled,
/// Attemtping to commit/reveal weights when disabled.
CommitRevealDisabled,
+ /// Invalid commit nonce.
+ InvalidCommitNonce,
+ /// Duplicate nonce.
+ DuplicateNonce,
+ // /// Non continuous nonce.
+ ... | Deliberately commented out? |
subtensor | github_2023 | others | 599 | opentensor | orriin | @@ -917,15 +919,15 @@ pub mod pallet {
pub type AdjustmentAlpha<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultAdjustmentAlpha<T>>;
- #[pallet::storage] // --- MAP (netuid, who) --> (hash, weight) | Returns the hash and weight committed by an account for a given netuid.
+ #[pall... | Does this need a migration? |
subtensor | github_2023 | others | 599 | opentensor | camfairchild | @@ -917,17 +919,22 @@ pub mod pallet {
pub type AdjustmentAlpha<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultAdjustmentAlpha<T>>;
- #[pallet::storage] // --- MAP (netuid, who) --> (hash, weight) | Returns the hash and weight committed by an account for a given netuid.
+ #[pall... | Getters are removed in Polkadot 1.11.0 |
subtensor | github_2023 | others | 599 | opentensor | camfairchild | @@ -40,11 +54,36 @@ impl<T: Config> Pallet<T> {
Error::<T>::WeightsCommitNotAllowed
);
- WeightCommits::<T>::insert(
- netuid,
- &who,
- (commit_hash, Self::get_current_block_as_u64()),
- );
+ // Check if the nonce is greater than the last pr... | Is this error useful? We accomplish the same thing, more generically, with the greater than latest nonce check.
Also removes a few reads versus just one we do anyway. |
subtensor | github_2023 | others | 599 | opentensor | camfairchild | @@ -1833,19 +1853,226 @@ fn test_commit_reveal_bad_salt_fail() {
weight_values.clone(),
bad_salt.clone(),
version_key,
+ nonce
),
Error::<Test>::InvalidRevealCommitHashNotMatch
);
});
}
+#[test]
+fn test_multipl... | Also test for out-of-order reveal. |
subtensor | github_2023 | others | 599 | opentensor | open-junius | @@ -474,3 +488,48 @@ pub fn migrate_to_v2_fixed_total_stake<T: Config>() -> Weight {
Weight::zero()
}
}
+
+pub fn migrate_to_v7_weight_commits<T: Config>() -> Weight {
+ let mut weight = T::DbWeight::get().reads(1);
+ let current_version = Pallet::<T>::on_chain_storage_version();
+
+ if current_... | can use drain() to remove old value. |
subtensor | github_2023 | others | 599 | opentensor | open-junius | @@ -474,3 +488,48 @@ pub fn migrate_to_v2_fixed_total_stake<T: Config>() -> Weight {
Weight::zero()
}
}
+
+pub fn migrate_to_v7_weight_commits<T: Config>() -> Weight {
+ let mut weight = T::DbWeight::get().reads(1);
+ let current_version = Pallet::<T>::on_chain_storage_version();
+
+ if current_... | get the total weight based on the count of map. not accumulate it each time. |
subtensor | github_2023 | others | 599 | opentensor | open-junius | @@ -126,5 +126,11 @@ mod errors {
CommitRevealEnabled,
/// Attemtping to commit/reveal weights when disabled.
CommitRevealDisabled,
+ /// Invalid commit nonce.
+ InvalidCommitNonce,
+ /// Duplicate nonce.
+ DuplicateNonce, | the error is not covered in tests. |
subtensor | github_2023 | others | 599 | opentensor | orriin | @@ -474,3 +488,48 @@ pub fn migrate_to_v2_fixed_total_stake<T: Config>() -> Weight {
Weight::zero()
}
}
+
+pub fn migrate_to_v7_weight_commits<T: Config>() -> Weight {
+ let mut weight = T::DbWeight::get().reads(1);
+ let current_version = Pallet::<T>::on_chain_storage_version();
+
+ if current_... | ```suggestion
if current_version == 6 {
```
Just in case |
subtensor | github_2023 | others | 599 | opentensor | orriin | @@ -474,3 +488,48 @@ pub fn migrate_to_v2_fixed_total_stake<T: Config>() -> Weight {
Weight::zero()
}
}
+
+pub fn migrate_to_v7_weight_commits<T: Config>() -> Weight { | This should be implemented with `OnRuntimeUpgrade`, `pre_upgrade` and `post_upgrade` methods implemented, and also added to the runtime (try-runtime checks should fail otherwise) |
subtensor | github_2023 | others | 599 | opentensor | orriin | @@ -40,11 +54,36 @@ impl<T: Config> Pallet<T> {
Error::<T>::WeightsCommitNotAllowed
);
- WeightCommits::<T>::insert(
- netuid,
- &who,
- (commit_hash, Self::get_current_block_as_u64()),
- );
+ // Check if the nonce is greater than the last pr... | Could you brick your subnet by using a nonce that's u64 max? Should we enforce cur nonce + 1 instead? |
subtensor | github_2023 | others | 599 | opentensor | orriin | @@ -448,28 +514,18 @@ impl<T: Config> Pallet<T> {
uids.len() <= subnetwork_n as usize
}
- pub fn can_commit(netuid: u16, who: &T::AccountId) -> bool {
- if let Some((_hash, commit_block)) = WeightCommits::<T>::get(netuid, who) {
- let interval: u64 = Self::get_commit_reveal_weights_... | Is this an expected code path? Should it log a warning or something? |
subtensor | github_2023 | others | 599 | opentensor | orriin | @@ -491,4 +547,47 @@ impl<T: Config> Pallet<T> {
false
}
+
+ /// Get the last processed nonce for a given netuid and account
+ ///
+ /// # Arguments
+ ///
+ /// * `netuid` - The network ID
+ /// * `account` - The account ID
+ ///
+ /// # Returns
+ ///
+ /// Returns the last... | I think we should just use `LastProcessedNonce::<T>::get(netuid, account)` directly in-line in our code, instead of adding all this boilerplate |
subtensor | github_2023 | others | 599 | opentensor | orriin | @@ -491,4 +547,47 @@ impl<T: Config> Pallet<T> {
false
}
+
+ /// Get the last processed nonce for a given netuid and account
+ ///
+ /// # Arguments
+ ///
+ /// * `netuid` - The network ID
+ /// * `account` - The account ID
+ ///
+ /// # Returns
+ ///
+ /// Returns the last... | I think we should just use `LastProcessedNonce::<T>::insert(netuid, account, nonce)` directly in-line in our code, instead of adding all this boilerplate |
subtensor | github_2023 | others | 599 | opentensor | sam0x17 | @@ -40,11 +54,36 @@ impl<T: Config> Pallet<T> {
Error::<T>::WeightsCommitNotAllowed
);
- WeightCommits::<T>::insert(
- netuid,
- &who,
- (commit_hash, Self::get_current_block_as_u64()),
- );
+ // Check if the nonce is greater than the last pr... | do we want to maybe make this configurable and/or are we happy with 10? |
subtensor | github_2023 | others | 777 | opentensor | gztensor | @@ -1,25 +1,89 @@
-/// Staking precompile's goal is to allow interaction between EVM users and smart contracts and
-/// subtensor staking functionality, namely add_stake, and remove_stake extrinsics.
-///
-/// Additional requirement is to preserve compatibility with Ethereum indexers, which requires
-/// no balance ... | `handle.context().caller` contains `msg.sender`, i.e. the address that called this contract. At the time when this method is called, the balance is already transferred to this precompile address, but `pallet_subtensor::Call::<Runtime>::add_stake` will attempt to remove it again from the `handle.context().caller` accoun... |
subtensor | github_2023 | others | 752 | opentensor | camfairchild | @@ -25,6 +25,29 @@ pub struct SubnetInfo<T: Config> {
emission_values: Compact<u64>,
burn: Compact<u64>,
owner: T::AccountId,
+}
+
+#[freeze_struct("65f931972fa13222")]
+#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)]
+pub struct SubnetInfov2<T: Config> {
+ netuid: Compact<u16>,
+ rho: Compa... | ```suggestion
network_connect: Vec<[Compact<u16>; 2]>,
``` |
subtensor | github_2023 | others | 752 | opentensor | open-junius | @@ -908,7 +1002,7 @@ impl<T: Config> Pallet<T> {
/// * 'NotEnoughBalanceToStake': If there isn't enough balance to stake for network registration.
/// * 'BalanceWithdrawalError': If an error occurs during balance withdrawal for network registration.
///
- pub fn user_add_network(
+ pub fn user_add_... | most of code in the same with user_add_network. we can remove user_add_network, call user_add_network_with_identity with identity as None |
subtensor | github_2023 | others | 752 | opentensor | open-junius | @@ -901,11 +901,8 @@ mod dispatches {
#[pallet::weight((Weight::from_parts(157_000_000, 0)
.saturating_add(T::DbWeight::get().reads(16))
.saturating_add(T::DbWeight::get().writes(30)), DispatchClass::Operational, Pays::No))]
- pub fn register_network(
- origin: OriginFor<T>,
- ... | just call Self::user_add_network_with_identity(origin, None) |
subtensor | github_2023 | others | 752 | opentensor | orriin | @@ -46,6 +46,10 @@ pub trait SubtensorCustomApi<BlockHash> {
fn get_subnet_info(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetsInfo")]
fn get_subnets_info(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
+ #[method(name = "subnetInfo_getSubn... | Why do all our custom rpc return bytes? It makes them annoying to consume, and returning a SCALE encoded type is no less efficient. |
subtensor | github_2023 | others | 752 | opentensor | orriin | @@ -1150,13 +1249,13 @@ impl<T: Config> Pallet<T> {
// --- 4. Remove netuid from added networks.
NetworksAdded::<T>::remove(netuid);
- // --- 6. Decrement the network counter.
- TotalNetworks::<T>::mutate(|n| *n = n.saturating_sub(1));
+ // --- 5. Decrement the network counter. | I suggest not using these numbers when we write new code / modify existing code, they can be annoying to maintain when you want to change the behavior of a fn |
subtensor | github_2023 | others | 752 | opentensor | orriin | @@ -901,11 +901,8 @@ mod dispatches {
#[pallet::weight((Weight::from_parts(157_000_000, 0)
.saturating_add(T::DbWeight::get().reads(16))
.saturating_add(T::DbWeight::get().writes(30)), DispatchClass::Operational, Pays::No))]
- pub fn register_network(
- origin: OriginFor<T>,
- ... | I suggest we put the contents of `user_add_network` inline here. |
subtensor | github_2023 | others | 752 | opentensor | orriin | @@ -1201,5 +1198,17 @@ mod dispatches {
) -> DispatchResult {
Self::do_set_subnet_identity(origin, netuid, subnet_name, github_repo, subnet_contact)
}
+
+ /// User register a new subnetwork
+ #[pallet::call_index(79)]
+ #[pallet::weight((Weight::from_parts(157_000_000... | Similarly, I suggest putting the contents of this fn inline here. |
subtensor | github_2023 | others | 752 | opentensor | orriin | @@ -1426,6 +1426,21 @@ impl_runtime_apis! {
result.encode()
}
+ fn get_subnet_info_v2(netuid: u16) -> Vec<u8> {
+ let _result = SubtensorModule::get_subnet_info_v2(netuid);
+ if _result.is_some() {
+ let result = _result.expect("Could not get SubnetInf... | Runtime apis can return Options / Results |
subtensor | github_2023 | others | 736 | opentensor | open-junius | @@ -152,6 +152,18 @@ pub mod pallet {
pub additional: Vec<u8>,
}
+ /// Struct for Prometheus.
+ pub type SubnetIdentityOf = SubnetIdentity;
+ /// Data structure for Prometheus information.
+ #[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)]
+ pub struct SubnetIden... | we need add freeze_struct for the struct. |
subtensor | github_2023 | others | 736 | opentensor | distributedstatemachine | @@ -894,17 +894,24 @@ impl<T: Config> Pallet<T> {
/// Facilitates user registration of a new subnetwork.
///
/// # Args:
- /// * 'origin': ('T::RuntimeOrigin'): The calling origin. Must be signed.
+ /// * `origin` (`T::RuntimeOrigin`): The calling origin. Must be signed.
+ /// * `identity` (`Opt... | Why have you decided on making idenitity optional ? |
subtensor | github_2023 | others | 736 | opentensor | distributedstatemachine | @@ -60,7 +60,7 @@ extern crate alloc;
#[frame_support::pallet]
pub mod pallet {
- use crate::migrations;
+ use crate::{freeze_struct, migrations}; | how do this line change affect the task ? |
subtensor | github_2023 | others | 745 | opentensor | distributedstatemachine | @@ -992,9 +992,8 @@ impl<T: Config> Pallet<T> {
/// * 'SubNetworkDoesNotExist': If the specified network does not exist.
/// * 'NotSubnetOwner': If the caller does not own the specified subnet.
///
- pub fn user_remove_network(origin: T::RuntimeOrigin, netuid: u16) -> dispatch::DispatchResult {
+ p... | fix comments |
subtensor | github_2023 | others | 745 | opentensor | distributedstatemachine | @@ -1100,7 +1105,10 @@ mod dispatches {
let duration: BlockNumberFor<T> = DissolveNetworkScheduleDuration::<T>::get();
let when: BlockNumberFor<T> = current_block.saturating_add(duration);
- let call = Call::<T>::dissolve_network { netuid };
+ let call = Call::<T>::diss... | Do we need to check that the user owns the network they are trying to dissolve here ? From the looks of it , anyone can dissolve a network , so I think we should just check if the user is the owner of the network |
subtensor | github_2023 | others | 745 | opentensor | distributedstatemachine | @@ -681,7 +681,7 @@ mod dispatches {
new_coldkey: T::AccountId,
) -> DispatchResultWithPostInfo {
// Ensure it's called with root privileges (scheduler has root privileges)
- ensure_root(origin.clone())?;
+ ensure_root(origin)?; | nevermind , the check is the method |
subtensor | github_2023 | others | 720 | opentensor | sam0x17 | @@ -0,0 +1,49 @@
+use semver::Version;
+use std::{
+ fs,
+ io::{Read, Seek, Write},
+ str::FromStr,
+};
+use toml_edit::{DocumentMut, Item, Value};
+
+const TOML_PATHS: [&str; 9] = [
+ "support/macros",
+ "pallets/commitments",
+ "pallets/collective",
+ "pallets/registry",
+ "pallets/subtensor",... | would be better if we could read this from STDIN then we don't even need a version file you can just specify it as an input to the program and use a workflow input on the github action that lets you specify the tag |
subtensor | github_2023 | others | 699 | opentensor | gztensor | @@ -603,7 +625,12 @@ pub mod pallet {
#[pallet::storage]
/// MAP ( hot ) --> take | Returns the hotkey delegation take. And signals that this key is open for delegation.
pub type Delegates<T: Config> =
- StorageMap<_, Blake2_128Concat, T::AccountId, u16, ValueQuery, DefaultDefaultTake<T>>;
+ ... | Does it need to be single map with tuple key instead of double map? |
subtensor | github_2023 | others | 699 | opentensor | gztensor | @@ -190,4 +190,102 @@ impl<T: Config> Pallet<T> {
pub fn get_parents(child: &T::AccountId, netuid: u16) -> Vec<(u64, T::AccountId)> {
ParentKeys::<T>::get(child, netuid)
}
+
+ /// Sets the childkey take for a given hotkey.
+ ///
+ /// This function allows a coldkey to set the childkey take f... | We also need to remove this value when we remove children for a parent key to avoid chain pollution. |
subtensor | github_2023 | others | 699 | opentensor | gztensor | @@ -858,7 +858,9 @@ parameter_types! {
pub const SubtensorInitialPruningScore : u16 = u16::MAX;
pub const SubtensorInitialBondsMovingAverage: u64 = 900_000;
pub const SubtensorInitialDefaultTake: u16 = 11_796; // 18% honest number.
- pub const SubtensorInitialMinTake: u16 = 5_898; // 9%
+ pub const... | I may remember this wrong from a voice conversation, but didn't we decide to make the default to be zero so that we don't deincentivise parent key delegation? |
subtensor | github_2023 | others | 699 | opentensor | gztensor | @@ -77,12 +77,16 @@ 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 InitialDefaultDelegateTake: u16 = 1... | We probably want to use the same default value as in Runtime for default childkey take. |
subtensor | github_2023 | others | 699 | opentensor | gztensor | @@ -130,6 +130,11 @@ impl<T: Config> Pallet<T> {
// --- 7.1. Insert my new children + proportion list into the map.
ChildKeys::<T>::insert(hotkey.clone(), netuid, children.clone());
+ if children.is_empty() {
+ // If there are no children, remove the ChildkeyTake value
+ ... | We should not remove `hotkey` childket take here: `hotkey` is a parent. If this parent is someone's child, even if it has no children, it should keep childkey take if it exists. |
subtensor | github_2023 | others | 699 | opentensor | open-junius | @@ -32,6 +34,7 @@ fn test_do_set_child_singular_success() {
});
}
+// 2: Attempt to set child in non-existent network
// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test children -- test_do_set_child_singular_network_does_not_exist --exact --nocapture
#[test]
fn test_do_set_child_singular_network_does_not_e... | It is duplicated with test_do_revoke_child_singular_network_does_not_exist, test_do_set_children_multiple_network_does_not_exist, test_do_revoke_children_multiple_network_does_not_exist. just test the network not exists. |
subtensor | github_2023 | others | 699 | opentensor | open-junius | @@ -862,6 +1220,10 @@ fn test_do_revoke_children_multiple_success() {
});
}
+// 29: Test revoking children when network does not exist
+// This test verifies the behavior when attempting to revoke children on a non-existent network:
+// - Attempts to revoke children on a network that doesn't exist
+// - Verifie... | The test code not aligned with test name. |
subtensor | github_2023 | others | 699 | opentensor | open-junius | @@ -560,6 +612,10 @@ fn test_do_set_children_multiple_success() {
});
}
+// 17: Test setting multiple children in a non-existent network
+// This test ensures that attempting to set multiple children in a non-existent network results in an error:
+// - Attempts to set children in a network that doesn't exist
+/... | The test code not aligned with test name. just one child and the number of child has no difference on a non-existed network. |
subtensor | github_2023 | others | 699 | opentensor | open-junius | @@ -453,6 +485,10 @@ fn test_do_revoke_child_singular_success() {
});
}
+// 13: Test revoking a child in a non-existent network
+// This test verifies that attempting to revoke a child in a non-existent network results in an error:
+// - Attempts to revoke a child in a network that doesn't exist
+// - Checks th... | can't see any child revoke. |
subtensor | github_2023 | others | 699 | opentensor | open-junius | @@ -583,6 +639,11 @@ fn test_do_set_children_multiple_network_does_not_exist() {
});
}
+// 18: Test setting multiple children with an invalid child
+// This test verifies that attempting to set multiple children with an invalid child (same as parent) results in an error:
+// - Sets up a network and registers a ... | just one child in the extrinsic. |
subtensor | github_2023 | others | 722 | opentensor | open-junius | @@ -131,6 +131,11 @@ impl<T: Config> Pallet<T> {
log::debug!("Accumulated emissions on hotkey {:?} for netuid {:?}: mining {:?}, validator {:?}", hotkey, *netuid, mining_emission, validator_emission);
}
} else {
+ // No epoch, increase blocks since last ... | It is ok to increase 1 block here. I just wondering why not record the block of last step. then blocks_since_last_step can be get by (current block - last step block). instead of plus 1 every time. |
subtensor | github_2023 | others | 724 | opentensor | distributedstatemachine | @@ -48,26 +48,26 @@ fi
if [[ $BUILD_BINARY == "1" ]]; then
echo "*** Building substrate binary..."
- cargo build --release --features "$FEATURES" --manifest-path "$BASE_DIR/Cargo.toml"
+ cargo build --workspace --profile=production --features "$FEATURES" --manifest-path "$BASE_DIR/Cargo.toml" | We do not want these for local net builds , as it just makes it alot longer. I think the original release build is sufficient |
subtensor | github_2023 | others | 724 | opentensor | distributedstatemachine | @@ -0,0 +1,11 @@
+use syn::File;
+
+use super::*;
+
+pub struct DummyLint;
+
+impl Lint for DummyLint { | Why do we need DummyLint? |
subtensor | github_2023 | others | 734 | opentensor | orriin | @@ -11,6 +11,7 @@ jobs:
check-spec-version:
name: Check spec_version bump
runs-on: SubtensorCI
+ if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-spec-version-bump') }} | Do we have something for check mainnet too? |
subtensor | github_2023 | others | 706 | opentensor | distributedstatemachine | @@ -59,28 +59,35 @@ impl<T: Config> Pallet<T> {
Error::<T>::NotEnoughBalanceToPaySwapColdKey
);
- // 6. Remove and burn the swap cost from the old coldkey's account
+ // 6. Swap identity if the old coldkey has one.
+ if Identities::<T>::contains_key(&old_coldkey)
+ ... | Please follow the existing pattern in the swap function i.e. we do not use separate functions , as it affects readability. Perform all the steps inline |
subtensor | github_2023 | others | 706 | opentensor | distributedstatemachine | @@ -106,4 +106,32 @@ impl<T: Config> Pallet<T> {
&& identity.description.len() <= 1024
&& identity.additional.len() <= 1024
}
+
+ /// Swaps the hotkey of a delegate identity from an old account ID to a new account ID.
+ ///
+ /// # Parameters
+ /// - `old_hotkey`: A reference ... | I understand the intuition behind returning a DispatchResult here , but we dont return errors for any of the other swap steps.
This is because the top level ensures should catch all these |
subtensor | github_2023 | others | 706 | opentensor | distributedstatemachine | @@ -827,3 +827,136 @@ fn test_migrate_set_hotkey_identities() {
);
});
}
+
+#[test]
+fn test_coldkey_swap_delegate_identity_updated() { | This test should be in coldkey swap, and also extend the main coldkey swap test to check that the identity is swapped |
subtensor | github_2023 | others | 707 | opentensor | distributedstatemachine | @@ -679,13 +677,14 @@ mod dispatches {
.saturating_add(T::DbWeight::get().writes(527)), DispatchClass::Operational, Pays::No))]
pub fn swap_coldkey(
origin: OriginFor<T>,
+ old_coldkey: T::AccountId, | Why are you changing the signature of the the swap_coldkey function ? Does the scheduler require it ? |
subtensor | github_2023 | others | 707 | opentensor | distributedstatemachine | @@ -30,12 +30,9 @@ 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, | why does this signature have to change? |
subtensor | github_2023 | others | 701 | opentensor | camfairchild | @@ -959,3 +959,38 @@ fn test_swap_hotkey_error_cases() {
assert_eq!(Balances::free_balance(coldkey), initial_balance - swap_cost);
});
}
+
+// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_hotkey_becomes_delegate --exact --nocapture
+#[test]
+fn test_swap_hotkey_becomes_dele... | ```suggestion
// Check that old_hotkey is still not a delegate
``` |
subtensor | github_2023 | others | 701 | opentensor | camfairchild | @@ -959,3 +959,38 @@ fn test_swap_hotkey_error_cases() {
assert_eq!(Balances::free_balance(coldkey), initial_balance - swap_cost);
});
}
+
+// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_hotkey_becomes_delegate --exact --nocapture
+#[test]
+fn test_swap_hotkey_becomes_dele... | ```suggestion
// Check that new_hotkey is NOT a delegate either
``` |
subtensor | github_2023 | others | 701 | opentensor | camfairchild | @@ -959,3 +959,38 @@ fn test_swap_hotkey_error_cases() {
assert_eq!(Balances::free_balance(coldkey), initial_balance - swap_cost);
});
}
+
+// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_hotkey_becomes_delegate --exact --nocapture
+#[test]
+fn test_swap_hotkey_becomes_dele... | ```suggestion
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_hotkey_does_not_become_delegate --exact --nocapture
#[test]
fn test_swap_hotkey_does_not_become_delegate() {
``` |
subtensor | github_2023 | others | 675 | opentensor | open-junius | @@ -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: 191,... | curious if the code change just to pass CI. no need to update runtime spec version. |
subtensor | github_2023 | others | 595 | opentensor | open-junius | @@ -26,7 +26,7 @@ pub mod pallet {
/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
- pub trait Config: frame_system::Config {
+ pub trait Config: frame_system::Config + pallet_subtensor::Config { | For TotalSubnetLocked, we can set it via a function as other hyperparameter. Why introduce the pallet_subtensor::Config this time. is anything special? |
subtensor | github_2023 | others | 595 | opentensor | open-junius | @@ -2051,6 +2099,42 @@ pub mod pallet {
pub fn dissolve_network(origin: OriginFor<T>, netuid: u16) -> DispatchResult {
Self::user_remove_network(origin, netuid)
}
+
+ /// Set the [`TotalIssuance`] storage value to the total account balances issued + the
+ /// total amount st... | Can we put it in on_finalize, then it can update total issuance automatically |
subtensor | github_2023 | others | 595 | opentensor | camfairchild | @@ -322,6 +323,16 @@ pub mod pallet {
pub type MinTake<T> = StorageValue<_, u16, ValueQuery, DefaultMinTake<T>>;
#[pallet::storage] // --- ITEM ( global_block_emission )
pub type BlockEmission<T> = StorageValue<_, u64, ValueQuery, DefaultBlockEmission<T>>;
+
+ /// The Subtensor [`TotalIssuance`] repre... | ```suggestion
/// It is comprised of three parts:
``` |
subtensor | github_2023 | others | 595 | opentensor | camfairchild | @@ -655,6 +666,9 @@ pub mod pallet {
#[pallet::storage] // --- MAP ( netuid ) --> subnet_locked
pub type SubnetLocked<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultSubnetLocked<T>>;
+ /// The total amount of locked tokens in subnets. | ```suggestion
/// The total amount of locked tokens in subnets for subnet registration.
``` |
subtensor | github_2023 | others | 595 | opentensor | camfairchild | @@ -322,6 +323,16 @@ pub mod pallet {
pub type MinTake<T> = StorageValue<_, u16, ValueQuery, DefaultMinTake<T>>;
#[pallet::storage] // --- ITEM ( global_block_emission )
pub type BlockEmission<T> = StorageValue<_, u64, ValueQuery, DefaultBlockEmission<T>>;
+
+ /// The Subtensor [`TotalIssuance`] repre... | ```suggestion
/// separate accounting.
``` |
subtensor | github_2023 | others | 595 | opentensor | camfairchild | @@ -324,6 +324,13 @@ impl<T: Config> Pallet<T> {
}
pub fn set_subnet_locked_balance(netuid: u16, amount: u64) {
+ let prev_total = TotalSubnetLocked::<T>::get();
+ let prev = SubnetLocked::<T>::get(netuid);
+
+ // Deduct the prev amount and add the new amount to the total | ```suggestion
// Deduct the previous amount and add the new amount to the total
``` |
subtensor | github_2023 | others | 595 | opentensor | distributedstatemachine | @@ -2402,6 +2334,46 @@ pub mod pallet {
}
true
}
+
+ #[cfg(feature = "try-runtime")] | I like this alot . We should probably add more maps to this. |
subtensor | github_2023 | others | 595 | opentensor | distributedstatemachine | @@ -0,0 +1,46 @@
+use frame_support::traits::{fungible, OnRuntimeUpgrade};
+
+use crate::*;
+
+pub struct Migration;
+
+impl OnRuntimeUpgrade for Migration { | What is the advantage of having this migration in the runtime? I find it confusing that we have some migrations in the pallet , and some in the runtime. Can we move it to the subtensor module? |
subtensor | github_2023 | others | 595 | opentensor | distributedstatemachine | @@ -1035,6 +1035,18 @@ pub mod pallet {
T::Subtensor::ensure_subnet_owner_or_root(origin.clone(), netuid)?;
T::Subtensor::do_set_alpha_values(origin, netuid, alpha_low, alpha_high)
}
+
+ /// Sets the [`pallet_subtensor::TotalSubnetLocked`] value.
+ #[pallet::call_index(5... | Remove |
subtensor | github_2023 | others | 595 | opentensor | distributedstatemachine | @@ -1183,6 +1183,22 @@ fn test_sudo_set_target_stakes_per_interval() {
});
}
+#[test]
+fn test_set_total_subnet_locked_ok() { | Remove |
subtensor | github_2023 | others | 595 | opentensor | distributedstatemachine | @@ -1219,6 +1235,21 @@ fn test_set_alpha_values_dispatch_info_ok() {
});
}
+#[test]
+fn test_set_total_subnet_locked_not_sudo() {
+ new_test_ext().execute_with(|| { | Remove all tests |
subtensor | github_2023 | others | 638 | opentensor | keithtensor | @@ -1051,7 +1034,7 @@ impl<T: Config> Pallet<T> {
NetworkModality::<T>::insert(netuid, 0);
// --- 5. Increase total network count.
- TotalNetworks::<T>::mutate(|n| n.saturating_inc());
+ TotalNetworks::<T>::mutate(|n| *n = n.saturating_add(1)); | Why change this? |
subtensor | github_2023 | others | 638 | opentensor | camfairchild | @@ -483,10 +486,6 @@ impl<T: Config> Pallet<T> {
// --- 1. Ensure that the call originates from a signed source and retrieve the caller's account ID (coldkey).
let coldkey = ensure_signed(origin)?;
- ensure!(
- !Self::coldkey_in_arbitration(&coldkey),
- Error::<T>::Coldk... | Make sure to add this back in some way |
subtensor | github_2023 | others | 638 | opentensor | open-junius | @@ -0,0 +1,846 @@
+use frame_support::pallet_macros::pallet_section;
+
+/// A [`pallet_section`] that defines the errors for a pallet.
+/// This can later be imported into the pallet using [`import_section`].
+#[pallet_section]
+mod dispatches { | can we reset all the extrinsic's call_index, make them in order. don't know how to choose the next call index when add a new extrinsic |
subtensor | github_2023 | others | 638 | opentensor | gztensor | @@ -94,1031 +88,905 @@ pub mod pallet {
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);
- /// Configure the pallet by specifying the parameters and types on which it depends.
- #[pallet::config]
- pub trait Config: frame_system::Config {
- /// Because this pallet emits e... | This is inaccurate. According to coinmarketcap, we only have 7M TAO in circulation, and this value can change, it cannot be hardcoded. |
subtensor | github_2023 | others | 638 | opentensor | gztensor | @@ -0,0 +1,846 @@
+use frame_support::pallet_macros::pallet_section;
+
+/// A [`pallet_section`] that defines the errors for a pallet.
+/// This can later be imported into the pallet using [`import_section`].
+#[pallet_section]
+mod dispatches {
+ /// Dispatchable functions allow users to interact with the pallet an... | Is it more user friendly to remove this extrinsic? Users may think it succeeded if they call it with btcli. |
subtensor | github_2023 | others | 638 | opentensor | gztensor | @@ -0,0 +1,75 @@
+use frame_support::pallet_macros::pallet_section;
+
+/// A [`pallet_section`] that defines the events for a pallet.
+/// This can later be imported into the pallet using [`import_section`].
+#[pallet_section]
+mod hooks {
+ // ================
+ // ==== Hooks =====
+ // ================
+ ... | Since we're cleaning up, we should remove migrations that have already happened. |
subtensor | github_2023 | others | 638 | opentensor | gztensor | @@ -0,0 +1,430 @@
+use super::*;
+use frame_support::{
+ storage::IterableStorageDoubleMap,
+ traits::{
+ tokens::{
+ fungible::{Balanced as _, Inspect as _, Mutate as _},
+ Fortitude, Precision, Preservation,
+ },
+ Imbalance,
+ },
+};
+
+impl<T: Config> Pallet<T> {
... | We should probably introduce some minimum stake to protect Stake map from dust |
subtensor | github_2023 | others | 626 | opentensor | distributedstatemachine | @@ -155,6 +155,19 @@ impl<T: Config> Pallet<T> {
let min_take = MinTake::<T>::get();
ensure!(take >= min_take, Error::<T>::DelegateTakeTooLow);
+ // Enforce the rate limit (independently on do_add_stake rate limits)
+ let block: u64 = Self::get_current_block_as_u64();
+ ensure!(... | Can we do this afer we insert into the storage map ? |
subtensor | github_2023 | others | 626 | opentensor | camfairchild | @@ -155,9 +155,22 @@ impl<T: Config> Pallet<T> {
let min_take = MinTake::<T>::get();
ensure!(take >= min_take, Error::<T>::DelegateTakeTooLow);
+ // Enforce the rate limit (independently on do_add_stake rate limits) | ```suggestion
// Enforce the rate limit (independent of do_add_stake rate limits)
``` |
subtensor | github_2023 | others | 626 | opentensor | camfairchild | @@ -3136,6 +3139,132 @@ fn test_rate_limits_enforced_on_increase_take() {
});
}
+// Test rate-limiting on decrease_take + increase_take
+#[test]
+fn test_rate_limits_enforced_on_increase_take_after_decrease() {
+ new_test_ext(1).execute_with(|| {
+ // Make account
+ let hotkey0 = U256::from(1);... | Is this the expected behaviour? imo, one should be able to decrease without rate limit, but not increase until after the rate limit since the last change (increase *or* decrease) |
subtensor | github_2023 | others | 541 | opentensor | distributedstatemachine | @@ -38,61 +37,66 @@ impl<T: Config> Pallet<T> {
// --- 2. Run the root epoch function which computes the block emission for each subnet.
// coinbase --> root() --> subnet_block_emission
- match Self::root_epoch( current_block ) { Ok(_) => (), Err(e) => {log::trace!("Error while running root e... | should this be saturating_add @open-junius ? |
subtensor | github_2023 | others | 522 | opentensor | orriin | @@ -9,6 +9,22 @@ impl<T: Config> Pallet<T> {
SubnetworkN::<T>::get(netuid)
}
+ pub fn set_emission_for_uid(netuid: u16, neuron_uid: u16, emission: u64) {
+ Emission::<T>::mutate(netuid, |v| v[neuron_uid as usize] = emission); | Could this direct indexing panic? cc @keithtensor |
subtensor | github_2023 | others | 522 | opentensor | orriin | @@ -9,6 +9,22 @@ impl<T: Config> Pallet<T> {
SubnetworkN::<T>::get(netuid)
}
+ pub fn set_emission_for_uid(netuid: u16, neuron_uid: u16, emission: u64) {
+ Emission::<T>::mutate(netuid, |v| v[neuron_uid as usize] = emission);
+ }
+ pub fn set_trust_for_uid(netuid: u16, neuron_uid: u16, t... | Instead of creating a layer of indirection, I would just do these `::mutate` operations inline where they are needed. Makes the code more clear, and faster to understand what it is doing. |
subtensor | github_2023 | others | 522 | opentensor | sam0x17 | @@ -45,6 +45,16 @@ impl<T: Config> Pallet<T> {
Uids::<T>::insert(netuid, new_hotkey.clone(), uid_to_replace); // Make uid - hotkey association.
BlockAtRegistration::<T>::insert(netuid, uid_to_replace, block_number); // Fill block at registration.
IsNetworkMember::<T>::insert(new_hotkey.clone(... | Would be nice to pull this out into a function |
subtensor | github_2023 | others | 522 | opentensor | open-junius | @@ -9,6 +9,15 @@ impl<T: Config> Pallet<T> {
SubnetworkN::<T>::get(netuid)
}
+ /// Resets the trust, emission, consensus, incentive, dividends of the neuron to default
+ pub fn clear_neuron(netuid: u16, neuron_uid: u16) {
+ Emission::<T>::mutate(netuid, |v| v[neuron_uid as usize] = 0); | can you add the length check before index with neuron_uid. |
subtensor | github_2023 | others | 522 | opentensor | distributedstatemachine | @@ -9,6 +9,26 @@ impl<T: Config> Pallet<T> {
SubnetworkN::<T>::get(netuid)
}
+ fn clear_element_at<N>(position: u16) -> impl Fn(&mut Vec<N>) | We are almost there! can you please add doc comments to this , as it would break some lints down the line.
I will get this approved today , and move it through our deployment process. I estimate this change would be on testnet in about 2 weeks |
subtensor | github_2023 | others | 439 | opentensor | distributedstatemachine | @@ -206,6 +206,7 @@ pub fn sigmoid_safe(input: I32F32, rho: I32F32, kappa: I32F32) -> I32F32 {
// Returns a bool vector where an item is true if the vector item is in topk values.
#[allow(dead_code, clippy::indexing_slicing)]
+#[test_fuzz::test_fuzz] | Is it possible to add bounds to these? My fear is that the fuzzer would run iterations on values outside what is realistic. |
subtensor | github_2023 | others | 425 | opentensor | distributedstatemachine | @@ -168,6 +170,11 @@ parameter_types! {
pub const SenateMaxMembers: u32 = 12;
}
+// Configure collective pallet for Subnet Owners
+parameter_types! { // Based on the number of u16::MAX subnets
+ pub const SubnetOwnersMaxMembers: u32 = u16::MAX as u32; | @camfairchild this need to change , based on the fact that we have increased the limit on subnets to 31. We also need to account for when users dissolve their networks (subnet 25 recently did this) |
subtensor | github_2023 | others | 245 | opentensor | camfairchild | @@ -181,15 +181,22 @@ impl<T: Config> Pallet<T> {
// --- 17. Set the activity for the weights on this network.
Self::set_last_update_for_uid(netuid, neuron_uid, current_block);
- // --- 18. Emit the tracking event.
+ // --- 18. Set the activity for the minors on this network.
+ ... | There is no logic to check if the uid is a validator or a miner |
subtensor | github_2023 | others | 245 | opentensor | camfairchild | @@ -181,15 +181,22 @@ impl<T: Config> Pallet<T> {
// --- 17. Set the activity for the weights on this network.
Self::set_last_update_for_uid(netuid, neuron_uid, current_block);
- // --- 18. Emit the tracking event.
+ // --- 18. Set the activity for the minors on this network. | Why should this run every time any key sets weights? This will use up a lot of resources each call to set_weights. |
subtensor | github_2023 | others | 631 | opentensor | sam0x17 | @@ -429,30 +429,4 @@ reveal_weights {
}: reveal_weights(RawOrigin::Signed(hotkey.clone()), netuid, uids, weight_values, salt, version_key)
- schedule_coldkey_swap { | I see no harm in leaving the benchmark in here, unless it creates compile errors? Benchmarking stuff is already `#[cfg(test)]` internally (I am 90% sure of this haven written the benchmarking v2 syntax at parity ;) ) so that should be 100% compatible with your `#[cfg(test)]` change unless there is some additional issue... |
subtensor | github_2023 | others | 631 | opentensor | sam0x17 | @@ -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: 194,... | ? |
subtensor | github_2023 | others | 631 | opentensor | gztensor | @@ -31,8 +31,9 @@ impl<T: Config> Pallet<T> {
new_hotkey: &T::AccountId,
) -> DispatchResultWithPostInfo {
let coldkey = ensure_signed(origin)?;
+
ensure!(
- !Self::coldkey_in_arbitration(&coldkey),
+ !Self::coldkey_in_arbitration(&old_coldkey), | This is good as it was:
```rust
!Self::coldkey_in_arbitration(&coldkey),
``` |
subtensor | github_2023 | others | 631 | opentensor | gztensor | @@ -189,15 +215,15 @@ impl<T: Config> Pallet<T> {
///
/// This function calculates the remaining arbitration period by subtracting the current block number
/// from the arbitration block number of the coldkey.
- // pub fn get_remaining_arbitration_period(coldkey: &T::AccountId) -> u64 {
- // le... | This method is still unused, we don't need it. |
subtensor | github_2023 | others | 644 | opentensor | sam0x17 | @@ -1420,7 +1423,7 @@ pub mod pallet {
.saturating_add(migration::migrate_populate_owned::<T>())
// Populate StakingHotkeys map for coldkey swap. Doesn't update storage vesion.
.saturating_add(migration::migrate_populate_staking_hotkeys::<T>())
- // Fix ... | ```suggestion
// Fix total coldkey stake.
``` |
subtensor | github_2023 | others | 633 | opentensor | sam0x17 | @@ -907,6 +952,39 @@ impl<T: Config> Pallet<T> {
TotalColdkeyStake::<T>::get(new_coldkey)
);
}
+
+
+ pub fn swap_hotfix(old_coldkey: &T::AccountId, new_coldkey: &T::AccountId) {
+
+ let weight = T::DbWeight::get().reads_writes(2, 1); | this variable is unused |
subtensor | github_2023 | others | 633 | opentensor | open-junius | @@ -851,7 +851,8 @@ impl<T: Config> Pallet<T> {
log::info!("Transferring stake for hotkey {:?}: {}", hotkey, stake);
if stake > 0 {
// Insert the stake for the hotkey and new coldkey
- Stake::<T>::insert(hotkey, new_coldkey, stake);
+ let old_stak... | can use mutate to add stake |
subtensor | github_2023 | others | 633 | opentensor | open-junius | @@ -861,6 +862,52 @@ impl<T: Config> Pallet<T> {
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 2));
}
}
+ log::info!(
+ "Starting transfer of delegated stakes for old coldkey: {:?}",
+ old_coldkey
+ );
+
+ for staking_hotkey... | no weight for get and remove. |
subtensor | github_2023 | others | 490 | opentensor | open-junius | @@ -1903,6 +1903,15 @@ pub mod pallet {
Self::do_root_register(origin, hotkey)
}
+ /// Attempt to adjust the senate membership to include a hotkey
+ #[pallet::call_index(63)]
+ #[pallet::weight((Weight::from_parts(0, 0)
+ .saturating_add(T::DbWeight::get().reads(0))
+ .sat... | Pay::No is fine for call from sudo. But the extrinsic can be called by any coldkey. The use may attach the chain by sending too many extrinsics. |
subtensor | github_2023 | others | 620 | opentensor | keithtensor | @@ -1301,21 +1334,29 @@ pub mod pallet {
// * 'n': (BlockNumberFor<T>):
// - The number of the block we are initializing.
fn on_initialize(_block_number: BlockNumberFor<T>) -> Weight {
+ // Unstake all and transfer pending coldkeys
+ let swap_weight = match Self::swap... | We do need to be careful about how long this operation will take on average, otherwise it may brick the chain. |
subtensor | github_2023 | others | 620 | opentensor | keithtensor | @@ -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... | What we could do is check whether `source_coldkeys` is greater than `MAX_ALLOWED_COLDKEYS_TO_SWAP_PER_BLOCK`, and if it is, then we truncate this vector, putting the remaining coldkeys back into the `ColdKeysToSwapAtBlock`, albeit in `current_block + 1`. |
subtensor | github_2023 | others | 620 | opentensor | orriin | @@ -146,5 +146,13 @@ mod errors {
NoBalanceToTransfer,
/// Same coldkey
SameColdkey,
+ /// The coldkey is in arbitration
+ ColdkeyIsInArbitration,
+ /// The new coldkey is already registered for the drain
+ DuplicateColdkey,
+ /// Error thrown on a coldkey s... | Can we make swap errors more specific? Otherwise may be difficult to pinpoint exactly what went wrong |
subtensor | github_2023 | others | 620 | opentensor | orriin | @@ -851,113 +869,74 @@ impl<T: Config> Pallet<T> {
}
}
- /// Unstakes all tokens associated with a hotkey and transfers them to a new coldkey.
- ///
- /// This function performs the following operations:
- /// 1. Verifies that the hotkey exists and is owned by the current coldkey.
- /// 2... | Why is all this stuff commented out? |
subtensor | github_2023 | others | 620 | opentensor | orriin | @@ -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... | Can just use ? syntax I think |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.