Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RAO Ugrade] Devnet-ready -> Devnet #1262

Merged
merged 22 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,885 changes: 739 additions & 1,146 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pallets/admin-utils/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ parameter_types! {
pub const InitialTxDelegateTakeRateLimit: u64 = 0; // Disable rate limit for testing
pub const InitialTxChildKeyTakeRateLimit: u64 = 0; // Disable rate limit for testing
pub const InitialBurn: u64 = 0;
pub const InitialMinBurn: u64 = 0;
pub const InitialMinBurn: u64 = 500_000;
pub const InitialMaxBurn: u64 = 1_000_000_000;
pub const InitialValidatorPruneLen: u64 = 0;
pub const InitialScalingLawPower: u16 = 50;
Expand Down
8 changes: 4 additions & 4 deletions pallets/collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ benchmarks_instance_pallet! {
// Whitelist voter account from further DB operations.
let voter_key = frame_system::Account::<T>::hashed_key_for(&voter);
frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into());
}: close(SystemOrigin::Signed(voter), last_hash, index, Weight::MAX, bytes_in_storage)
}: close(SystemOrigin::Root, last_hash, index, Weight::MAX, bytes_in_storage)
verify {
// The last proposal is removed.
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
Expand Down Expand Up @@ -393,7 +393,7 @@ benchmarks_instance_pallet! {
index, approve,
)?;

}: close(SystemOrigin::Signed(caller), last_hash, index, Weight::MAX, bytes_in_storage)
}: close(SystemOrigin::Root, last_hash, index, Weight::MAX, bytes_in_storage)
verify {
// The last proposal is removed.
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
Expand Down Expand Up @@ -473,7 +473,7 @@ benchmarks_instance_pallet! {
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);

// Prime nay will close it as disapproved
}: close(SystemOrigin::Signed(caller), last_hash, index, Weight::MAX, bytes_in_storage)
}: close(SystemOrigin::Root, last_hash, index, Weight::MAX, bytes_in_storage)
verify {
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
assert_last_event::<T, I>(Event::Disapproved { proposal_hash: last_hash }.into());
Expand Down Expand Up @@ -542,7 +542,7 @@ benchmarks_instance_pallet! {
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);

// Prime aye will close it as approved
}: close(SystemOrigin::Signed(caller), last_hash, p - 1, Weight::MAX, bytes_in_storage)
}: close(SystemOrigin::Root, last_hash, p - 1, Weight::MAX, bytes_in_storage)
verify {
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
assert_last_event::<T, I>(Event::Executed { proposal_hash: last_hash, result: Ok(()) }.into());
Expand Down
46 changes: 20 additions & 26 deletions pallets/collective/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ fn close_works() {
System::set_block_number(3);
assert_noop!(
Collective::close(
RuntimeOrigin::signed(4),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand All @@ -310,7 +310,7 @@ fn close_works() {

System::set_block_number(4);
assert_ok!(Collective::close(
RuntimeOrigin::signed(4),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand Down Expand Up @@ -370,7 +370,7 @@ fn proposal_weight_limit_works_on_approve() {
System::set_block_number(4);
assert_noop!(
Collective::close(
RuntimeOrigin::signed(4),
RuntimeOrigin::root(),
hash,
0,
proposal_weight - Weight::from_parts(100, 0),
Expand All @@ -379,7 +379,7 @@ fn proposal_weight_limit_works_on_approve() {
Error::<Test, Instance1>::ProposalWeightLessThanDispatchCallWeight
);
assert_ok!(Collective::close(
RuntimeOrigin::signed(4),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand Down Expand Up @@ -409,7 +409,7 @@ fn proposal_weight_limit_ignored_on_disapprove() {
// No votes, this proposal wont pass
System::set_block_number(4);
assert_ok!(Collective::close(
RuntimeOrigin::signed(4),
RuntimeOrigin::root(),
hash,
0,
proposal_weight - Weight::from_parts(100, 0),
Expand Down Expand Up @@ -442,7 +442,7 @@ fn close_with_prime_works() {

System::set_block_number(4);
assert_ok!(Collective::close(
RuntimeOrigin::signed(4),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand Down Expand Up @@ -502,7 +502,7 @@ fn close_with_voting_prime_works() {

System::set_block_number(4);
assert_ok!(Collective::close(
RuntimeOrigin::signed(4),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand Down Expand Up @@ -583,7 +583,7 @@ fn close_with_no_prime_but_majority_works() {

System::set_block_number(4);
assert_ok!(CollectiveMajority::close(
RuntimeOrigin::signed(4),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand Down Expand Up @@ -1109,7 +1109,7 @@ fn motions_all_first_vote_free_works() {

let proposal_weight = proposal.get_dispatch_info().weight;
let close_rval: DispatchResultWithPostInfo = Collective::close(
RuntimeOrigin::signed(2),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand All @@ -1120,7 +1120,7 @@ fn motions_all_first_vote_free_works() {
// Trying to close the proposal, which is already closed
// Error: "ProposalNotExists" with Pays::Yes.
let close_rval: DispatchResultWithPostInfo = Collective::close(
RuntimeOrigin::signed(2),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand Down Expand Up @@ -1148,7 +1148,7 @@ fn motions_reproposing_disapproved_works() {
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, false));

assert_ok!(Collective::close(
RuntimeOrigin::signed(2),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand Down Expand Up @@ -1186,7 +1186,7 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() {
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
assert_ok!(Collective::close(
RuntimeOrigin::signed(2),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand Down Expand Up @@ -1243,7 +1243,7 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() {
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 1, true));
assert_ok!(Collective::vote(RuntimeOrigin::signed(3), hash, 1, true));
assert_ok!(Collective::close(
RuntimeOrigin::signed(2),
RuntimeOrigin::root(),
hash,
1,
proposal_weight,
Expand Down Expand Up @@ -1315,7 +1315,7 @@ fn motions_disapproval_works() {
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, false));
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, false));
assert_ok!(Collective::close(
RuntimeOrigin::signed(2),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand Down Expand Up @@ -1374,7 +1374,7 @@ fn motions_approval_works() {
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
assert_ok!(Collective::close(
RuntimeOrigin::signed(2),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand Down Expand Up @@ -1448,7 +1448,7 @@ fn motion_with_no_votes_closes_with_disapproval() {
// an approving or disapproving simple majority due to the lack of votes.
assert_noop!(
Collective::close(
RuntimeOrigin::signed(2),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand All @@ -1462,7 +1462,7 @@ fn motion_with_no_votes_closes_with_disapproval() {
System::set_block_number(closing_block);
// we can successfully close the motion.
assert_ok!(Collective::close(
RuntimeOrigin::signed(2),
RuntimeOrigin::root(),
hash,
0,
proposal_weight,
Expand Down Expand Up @@ -1507,25 +1507,19 @@ fn close_disapprove_does_not_care_about_weight_or_len() {
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
// It will not close with bad weight/len information
assert_noop!(
Collective::close(RuntimeOrigin::signed(2), hash, 0, Weight::zero(), 0),
Collective::close(RuntimeOrigin::root(), hash, 0, Weight::zero(), 0),
Error::<Test, Instance1>::ProposalLengthBoundLessThanProposalLength,
);
assert_noop!(
Collective::close(
RuntimeOrigin::signed(2),
hash,
0,
Weight::zero(),
proposal_len
),
Collective::close(RuntimeOrigin::root(), hash, 0, Weight::zero(), proposal_len),
Error::<Test, Instance1>::ProposalWeightLessThanDispatchCallWeight,
);
// Now we make the proposal fail
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, false));
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, false));
// It can close even if the weight/len information is bad
assert_ok!(Collective::close(
RuntimeOrigin::signed(2),
RuntimeOrigin::root(),
hash,
0,
Weight::zero(),
Expand Down
27 changes: 23 additions & 4 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,17 @@ impl<T: Config> Pallet<T> {
}
log::debug!("alpha_dividends: {:?}", alpha_dividends);
log::debug!("root_dividends: {:?}", root_dividends);
log::debug!("total_root_divs: {:?}", total_root_divs);

// Compute root divs as TAO. Here we take
let mut tao_dividends: BTreeMap<T::AccountId, I96F32> = BTreeMap::new();
for (hotkey, root_divs) in root_dividends {
// Root proportion.
let root_share: I96F32 = root_divs.checked_div(total_root_divs).unwrap_or(zero);
log::debug!("hotkey: {:?}, root_share: {:?}", hotkey, root_share);
// Root proportion in TAO
let root_tao: I96F32 = asfloat!(pending_tao).saturating_mul(root_share);
log::debug!("hotkey: {:?}, root_tao: {:?}", hotkey, root_tao);
// Record root dividends as TAO.
tao_dividends
.entry(hotkey)
Expand All @@ -358,6 +361,12 @@ impl<T: Config> Pallet<T> {
if let Ok(owner_coldkey) = SubnetOwner::<T>::try_get(netuid) {
if let Ok(owner_hotkey) = SubnetOwnerHotkey::<T>::try_get(netuid) {
// Increase stake for owner hotkey and coldkey.
log::debug!(
"owner_hotkey: {:?} owner_coldkey: {:?}, owner_cut: {:?}",
owner_hotkey,
owner_coldkey,
owner_cut
);
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
&owner_hotkey,
&owner_coldkey,
Expand All @@ -370,6 +379,7 @@ impl<T: Config> Pallet<T> {
// Distribute mining incentives.
for (hotkey, incentive) in incentives {
// Increase stake for miner.
log::debug!("incentives: hotkey: {:?}", incentive);
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey.clone(),
&Owner::<T>::get(hotkey.clone()),
Expand All @@ -381,21 +391,21 @@ impl<T: Config> Pallet<T> {
// Distribute alpha divs.
let _ = AlphaDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
for (hotkey, mut alpha_divs) in alpha_dividends {
log::debug!("hotkey: {:?} alpha_divs: {:?}", hotkey, alpha_divs);

// Get take prop
let alpha_take: I96F32 =
Self::get_hotkey_take_float(&hotkey).saturating_mul(alpha_divs);
// Remove take prop from alpha_divs
alpha_divs = alpha_divs.saturating_sub(alpha_take);
// Give the validator their take.
log::debug!("hotkey: {:?} alpha_take: {:?}", hotkey, alpha_take);
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey,
&Owner::<T>::get(hotkey.clone()),
netuid,
tou64!(alpha_take),
);
// Give all other nominators.
log::debug!("hotkey: {:?} alpha_divs: {:?}", hotkey, alpha_divs);
Self::increase_stake_for_hotkey_on_subnet(&hotkey.clone(), netuid, tou64!(alpha_divs));
// Record dividends for this hotkey.
AlphaDividendsPerSubnet::<T>::mutate(netuid, hotkey.clone(), |divs| {
Expand All @@ -406,19 +416,20 @@ impl<T: Config> Pallet<T> {
// Distribute root tao divs.
let _ = TaoDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
for (hotkey, mut root_tao) in tao_dividends {
log::debug!("hotkey: {:?} root_tao: {:?}", hotkey, root_tao);
// Get take prop
let tao_take: I96F32 = Self::get_hotkey_take_float(&hotkey).saturating_mul(root_tao);
// Remove take prop from root_tao
root_tao = root_tao.saturating_sub(tao_take);
// Give the validator their take.
log::debug!("hotkey: {:?} tao_take: {:?}", hotkey, tao_take);
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey,
&Owner::<T>::get(hotkey.clone()),
Self::get_root_netuid(),
tou64!(tao_take),
);
// Give rest to nominators.
log::debug!("hotkey: {:?} root_tao: {:?}", hotkey, root_tao);
Self::increase_stake_for_hotkey_on_subnet(
&hotkey,
Self::get_root_netuid(),
Expand Down Expand Up @@ -580,10 +591,18 @@ impl<T: Config> Pallet<T> {
(remaining_emission.saturating_mul(emission_factor)).saturating_to_num::<u64>();

// Add the parent's emission to the distribution list
dividend_tuples.push((parent, parent_emission));
dividend_tuples.push((parent.clone(), parent_emission));

// Keep track of total emission distributed to parents
to_parents = to_parents.saturating_add(parent_emission);
log::debug!(
"Parent contribution for parent {:?} with contribution: {:?}, of total: {:?} of emission: {:?} gets: {:?}",
parent,
contribution,
total_contribution,
remaining_emission,
parent_emission
);
}
// Calculate the final emission for the hotkey itself.
// This includes the take left from the parents and the self contribution.
Expand Down
4 changes: 3 additions & 1 deletion pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ mod hooks {
.saturating_add(migrations::migrate_fix_is_network_member::migrate_fix_is_network_member::<T>())
.saturating_add(migrations::migrate_subnet_volume::migrate_subnet_volume::<T>())
// Upgrade identities to V2
.saturating_add(migrations::migrate_identities_v2::migrate_identities_to_v2::<T>());
.saturating_add(migrations::migrate_identities_v2::migrate_identities_to_v2::<T>())
// Set the min burn across all subnets to a new minimum
.saturating_add(migrations::migrate_set_min_burn::migrate_set_min_burn::<T>());
weight
}

Expand Down
7 changes: 5 additions & 2 deletions pallets/subtensor/src/migrations/migrate_rao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ pub fn migrate_rao<T: Config>() -> Weight {

// Convert subnets and give them lock.
// Set global weight to 18% from the start
TaoWeight::<T>::set(332_041_393_326_771_929);
// Set min lock
NetworkMinLockCost::<T>::set(1_000_000_000);
// Set tao weight.
TaoWeight::<T>::set(3_320_413_933_267_719_290);
for netuid in netuids.iter().clone() {
if *netuid == 0 {
// Give root a single RAO in pool to avoid any catestrophic division by zero.
SubnetAlphaIn::<T>::insert(netuid, 1);
SubnetAlphaIn::<T>::insert(netuid, 1_000_000_000);
SubnetMechanism::<T>::insert(netuid, 0); // Set to zero mechanism.
TokenSymbol::<T>::insert(netuid, Pallet::<T>::get_symbol_for_subnet(0));
continue;
Expand Down
Loading
Loading