Skip to content

Commit 29b6e36

Browse files
authored
Merge pull request #1262 from opentensor/devnet-ready
[RAO Ugrade] Devnet-ready -> Devnet
2 parents f97a6ce + c8eeef2 commit 29b6e36

File tree

12 files changed

+1440
-1195
lines changed

12 files changed

+1440
-1195
lines changed

Cargo.lock

Lines changed: 739 additions & 1146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pallets/admin-utils/src/tests/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ parameter_types! {
100100
pub const InitialTxDelegateTakeRateLimit: u64 = 0; // Disable rate limit for testing
101101
pub const InitialTxChildKeyTakeRateLimit: u64 = 0; // Disable rate limit for testing
102102
pub const InitialBurn: u64 = 0;
103-
pub const InitialMinBurn: u64 = 0;
103+
pub const InitialMinBurn: u64 = 500_000;
104104
pub const InitialMaxBurn: u64 = 1_000_000_000;
105105
pub const InitialValidatorPruneLen: u64 = 0;
106106
pub const InitialScalingLawPower: u16 = 50;

pallets/collective/src/benchmarking.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ benchmarks_instance_pallet! {
315315
// Whitelist voter account from further DB operations.
316316
let voter_key = frame_system::Account::<T>::hashed_key_for(&voter);
317317
frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into());
318-
}: close(SystemOrigin::Signed(voter), last_hash, index, Weight::MAX, bytes_in_storage)
318+
}: close(SystemOrigin::Root, last_hash, index, Weight::MAX, bytes_in_storage)
319319
verify {
320320
// The last proposal is removed.
321321
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
@@ -393,7 +393,7 @@ benchmarks_instance_pallet! {
393393
index, approve,
394394
)?;
395395

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

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

544544
// Prime aye will close it as approved
545-
}: close(SystemOrigin::Signed(caller), last_hash, p - 1, Weight::MAX, bytes_in_storage)
545+
}: close(SystemOrigin::Root, last_hash, p - 1, Weight::MAX, bytes_in_storage)
546546
verify {
547547
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
548548
assert_last_event::<T, I>(Event::Executed { proposal_hash: last_hash, result: Ok(()) }.into());

pallets/collective/src/tests.rs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn close_works() {
299299
System::set_block_number(3);
300300
assert_noop!(
301301
Collective::close(
302-
RuntimeOrigin::signed(4),
302+
RuntimeOrigin::root(),
303303
hash,
304304
0,
305305
proposal_weight,
@@ -310,7 +310,7 @@ fn close_works() {
310310

311311
System::set_block_number(4);
312312
assert_ok!(Collective::close(
313-
RuntimeOrigin::signed(4),
313+
RuntimeOrigin::root(),
314314
hash,
315315
0,
316316
proposal_weight,
@@ -370,7 +370,7 @@ fn proposal_weight_limit_works_on_approve() {
370370
System::set_block_number(4);
371371
assert_noop!(
372372
Collective::close(
373-
RuntimeOrigin::signed(4),
373+
RuntimeOrigin::root(),
374374
hash,
375375
0,
376376
proposal_weight - Weight::from_parts(100, 0),
@@ -379,7 +379,7 @@ fn proposal_weight_limit_works_on_approve() {
379379
Error::<Test, Instance1>::ProposalWeightLessThanDispatchCallWeight
380380
);
381381
assert_ok!(Collective::close(
382-
RuntimeOrigin::signed(4),
382+
RuntimeOrigin::root(),
383383
hash,
384384
0,
385385
proposal_weight,
@@ -409,7 +409,7 @@ fn proposal_weight_limit_ignored_on_disapprove() {
409409
// No votes, this proposal wont pass
410410
System::set_block_number(4);
411411
assert_ok!(Collective::close(
412-
RuntimeOrigin::signed(4),
412+
RuntimeOrigin::root(),
413413
hash,
414414
0,
415415
proposal_weight - Weight::from_parts(100, 0),
@@ -442,7 +442,7 @@ fn close_with_prime_works() {
442442

443443
System::set_block_number(4);
444444
assert_ok!(Collective::close(
445-
RuntimeOrigin::signed(4),
445+
RuntimeOrigin::root(),
446446
hash,
447447
0,
448448
proposal_weight,
@@ -502,7 +502,7 @@ fn close_with_voting_prime_works() {
502502

503503
System::set_block_number(4);
504504
assert_ok!(Collective::close(
505-
RuntimeOrigin::signed(4),
505+
RuntimeOrigin::root(),
506506
hash,
507507
0,
508508
proposal_weight,
@@ -583,7 +583,7 @@ fn close_with_no_prime_but_majority_works() {
583583

584584
System::set_block_number(4);
585585
assert_ok!(CollectiveMajority::close(
586-
RuntimeOrigin::signed(4),
586+
RuntimeOrigin::root(),
587587
hash,
588588
0,
589589
proposal_weight,
@@ -1109,7 +1109,7 @@ fn motions_all_first_vote_free_works() {
11091109

11101110
let proposal_weight = proposal.get_dispatch_info().weight;
11111111
let close_rval: DispatchResultWithPostInfo = Collective::close(
1112-
RuntimeOrigin::signed(2),
1112+
RuntimeOrigin::root(),
11131113
hash,
11141114
0,
11151115
proposal_weight,
@@ -1120,7 +1120,7 @@ fn motions_all_first_vote_free_works() {
11201120
// Trying to close the proposal, which is already closed
11211121
// Error: "ProposalNotExists" with Pays::Yes.
11221122
let close_rval: DispatchResultWithPostInfo = Collective::close(
1123-
RuntimeOrigin::signed(2),
1123+
RuntimeOrigin::root(),
11241124
hash,
11251125
0,
11261126
proposal_weight,
@@ -1148,7 +1148,7 @@ fn motions_reproposing_disapproved_works() {
11481148
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, false));
11491149

11501150
assert_ok!(Collective::close(
1151-
RuntimeOrigin::signed(2),
1151+
RuntimeOrigin::root(),
11521152
hash,
11531153
0,
11541154
proposal_weight,
@@ -1186,7 +1186,7 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() {
11861186
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
11871187
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
11881188
assert_ok!(Collective::close(
1189-
RuntimeOrigin::signed(2),
1189+
RuntimeOrigin::root(),
11901190
hash,
11911191
0,
11921192
proposal_weight,
@@ -1243,7 +1243,7 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() {
12431243
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 1, true));
12441244
assert_ok!(Collective::vote(RuntimeOrigin::signed(3), hash, 1, true));
12451245
assert_ok!(Collective::close(
1246-
RuntimeOrigin::signed(2),
1246+
RuntimeOrigin::root(),
12471247
hash,
12481248
1,
12491249
proposal_weight,
@@ -1315,7 +1315,7 @@ fn motions_disapproval_works() {
13151315
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, false));
13161316
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, false));
13171317
assert_ok!(Collective::close(
1318-
RuntimeOrigin::signed(2),
1318+
RuntimeOrigin::root(),
13191319
hash,
13201320
0,
13211321
proposal_weight,
@@ -1374,7 +1374,7 @@ fn motions_approval_works() {
13741374
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true));
13751375
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
13761376
assert_ok!(Collective::close(
1377-
RuntimeOrigin::signed(2),
1377+
RuntimeOrigin::root(),
13781378
hash,
13791379
0,
13801380
proposal_weight,
@@ -1448,7 +1448,7 @@ fn motion_with_no_votes_closes_with_disapproval() {
14481448
// an approving or disapproving simple majority due to the lack of votes.
14491449
assert_noop!(
14501450
Collective::close(
1451-
RuntimeOrigin::signed(2),
1451+
RuntimeOrigin::root(),
14521452
hash,
14531453
0,
14541454
proposal_weight,
@@ -1462,7 +1462,7 @@ fn motion_with_no_votes_closes_with_disapproval() {
14621462
System::set_block_number(closing_block);
14631463
// we can successfully close the motion.
14641464
assert_ok!(Collective::close(
1465-
RuntimeOrigin::signed(2),
1465+
RuntimeOrigin::root(),
14661466
hash,
14671467
0,
14681468
proposal_weight,
@@ -1507,25 +1507,19 @@ fn close_disapprove_does_not_care_about_weight_or_len() {
15071507
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true));
15081508
// It will not close with bad weight/len information
15091509
assert_noop!(
1510-
Collective::close(RuntimeOrigin::signed(2), hash, 0, Weight::zero(), 0),
1510+
Collective::close(RuntimeOrigin::root(), hash, 0, Weight::zero(), 0),
15111511
Error::<Test, Instance1>::ProposalLengthBoundLessThanProposalLength,
15121512
);
15131513
assert_noop!(
1514-
Collective::close(
1515-
RuntimeOrigin::signed(2),
1516-
hash,
1517-
0,
1518-
Weight::zero(),
1519-
proposal_len
1520-
),
1514+
Collective::close(RuntimeOrigin::root(), hash, 0, Weight::zero(), proposal_len),
15211515
Error::<Test, Instance1>::ProposalWeightLessThanDispatchCallWeight,
15221516
);
15231517
// Now we make the proposal fail
15241518
assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, false));
15251519
assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, false));
15261520
// It can close even if the weight/len information is bad
15271521
assert_ok!(Collective::close(
1528-
RuntimeOrigin::signed(2),
1522+
RuntimeOrigin::root(),
15291523
hash,
15301524
0,
15311525
Weight::zero(),

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,17 @@ impl<T: Config> Pallet<T> {
338338
}
339339
log::debug!("alpha_dividends: {:?}", alpha_dividends);
340340
log::debug!("root_dividends: {:?}", root_dividends);
341+
log::debug!("total_root_divs: {:?}", total_root_divs);
341342

342343
// Compute root divs as TAO. Here we take
343344
let mut tao_dividends: BTreeMap<T::AccountId, I96F32> = BTreeMap::new();
344345
for (hotkey, root_divs) in root_dividends {
345346
// Root proportion.
346347
let root_share: I96F32 = root_divs.checked_div(total_root_divs).unwrap_or(zero);
348+
log::debug!("hotkey: {:?}, root_share: {:?}", hotkey, root_share);
347349
// Root proportion in TAO
348350
let root_tao: I96F32 = asfloat!(pending_tao).saturating_mul(root_share);
351+
log::debug!("hotkey: {:?}, root_tao: {:?}", hotkey, root_tao);
349352
// Record root dividends as TAO.
350353
tao_dividends
351354
.entry(hotkey)
@@ -358,6 +361,12 @@ impl<T: Config> Pallet<T> {
358361
if let Ok(owner_coldkey) = SubnetOwner::<T>::try_get(netuid) {
359362
if let Ok(owner_hotkey) = SubnetOwnerHotkey::<T>::try_get(netuid) {
360363
// Increase stake for owner hotkey and coldkey.
364+
log::debug!(
365+
"owner_hotkey: {:?} owner_coldkey: {:?}, owner_cut: {:?}",
366+
owner_hotkey,
367+
owner_coldkey,
368+
owner_cut
369+
);
361370
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
362371
&owner_hotkey,
363372
&owner_coldkey,
@@ -370,6 +379,7 @@ impl<T: Config> Pallet<T> {
370379
// Distribute mining incentives.
371380
for (hotkey, incentive) in incentives {
372381
// Increase stake for miner.
382+
log::debug!("incentives: hotkey: {:?}", incentive);
373383
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
374384
&hotkey.clone(),
375385
&Owner::<T>::get(hotkey.clone()),
@@ -381,21 +391,21 @@ impl<T: Config> Pallet<T> {
381391
// Distribute alpha divs.
382392
let _ = AlphaDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
383393
for (hotkey, mut alpha_divs) in alpha_dividends {
384-
log::debug!("hotkey: {:?} alpha_divs: {:?}", hotkey, alpha_divs);
385-
386394
// Get take prop
387395
let alpha_take: I96F32 =
388396
Self::get_hotkey_take_float(&hotkey).saturating_mul(alpha_divs);
389397
// Remove take prop from alpha_divs
390398
alpha_divs = alpha_divs.saturating_sub(alpha_take);
391399
// Give the validator their take.
400+
log::debug!("hotkey: {:?} alpha_take: {:?}", hotkey, alpha_take);
392401
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
393402
&hotkey,
394403
&Owner::<T>::get(hotkey.clone()),
395404
netuid,
396405
tou64!(alpha_take),
397406
);
398407
// Give all other nominators.
408+
log::debug!("hotkey: {:?} alpha_divs: {:?}", hotkey, alpha_divs);
399409
Self::increase_stake_for_hotkey_on_subnet(&hotkey.clone(), netuid, tou64!(alpha_divs));
400410
// Record dividends for this hotkey.
401411
AlphaDividendsPerSubnet::<T>::mutate(netuid, hotkey.clone(), |divs| {
@@ -406,19 +416,20 @@ impl<T: Config> Pallet<T> {
406416
// Distribute root tao divs.
407417
let _ = TaoDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
408418
for (hotkey, mut root_tao) in tao_dividends {
409-
log::debug!("hotkey: {:?} root_tao: {:?}", hotkey, root_tao);
410419
// Get take prop
411420
let tao_take: I96F32 = Self::get_hotkey_take_float(&hotkey).saturating_mul(root_tao);
412421
// Remove take prop from root_tao
413422
root_tao = root_tao.saturating_sub(tao_take);
414423
// Give the validator their take.
424+
log::debug!("hotkey: {:?} tao_take: {:?}", hotkey, tao_take);
415425
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
416426
&hotkey,
417427
&Owner::<T>::get(hotkey.clone()),
418428
Self::get_root_netuid(),
419429
tou64!(tao_take),
420430
);
421431
// Give rest to nominators.
432+
log::debug!("hotkey: {:?} root_tao: {:?}", hotkey, root_tao);
422433
Self::increase_stake_for_hotkey_on_subnet(
423434
&hotkey,
424435
Self::get_root_netuid(),
@@ -580,10 +591,18 @@ impl<T: Config> Pallet<T> {
580591
(remaining_emission.saturating_mul(emission_factor)).saturating_to_num::<u64>();
581592

582593
// Add the parent's emission to the distribution list
583-
dividend_tuples.push((parent, parent_emission));
594+
dividend_tuples.push((parent.clone(), parent_emission));
584595

585596
// Keep track of total emission distributed to parents
586597
to_parents = to_parents.saturating_add(parent_emission);
598+
log::debug!(
599+
"Parent contribution for parent {:?} with contribution: {:?}, of total: {:?} of emission: {:?} gets: {:?}",
600+
parent,
601+
contribution,
602+
total_contribution,
603+
remaining_emission,
604+
parent_emission
605+
);
587606
}
588607
// Calculate the final emission for the hotkey itself.
589608
// This includes the take left from the parents and the self contribution.

pallets/subtensor/src/macros/hooks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ mod hooks {
7979
.saturating_add(migrations::migrate_fix_is_network_member::migrate_fix_is_network_member::<T>())
8080
.saturating_add(migrations::migrate_subnet_volume::migrate_subnet_volume::<T>())
8181
// Upgrade identities to V2
82-
.saturating_add(migrations::migrate_identities_v2::migrate_identities_to_v2::<T>());
82+
.saturating_add(migrations::migrate_identities_v2::migrate_identities_to_v2::<T>())
83+
// Set the min burn across all subnets to a new minimum
84+
.saturating_add(migrations::migrate_set_min_burn::migrate_set_min_burn::<T>());
8385
weight
8486
}
8587

pallets/subtensor/src/migrations/migrate_rao.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ pub fn migrate_rao<T: Config>() -> Weight {
6161

6262
// Convert subnets and give them lock.
6363
// Set global weight to 18% from the start
64-
TaoWeight::<T>::set(332_041_393_326_771_929);
64+
// Set min lock
65+
NetworkMinLockCost::<T>::set(1_000_000_000);
66+
// Set tao weight.
67+
TaoWeight::<T>::set(3_320_413_933_267_719_290);
6568
for netuid in netuids.iter().clone() {
6669
if *netuid == 0 {
6770
// Give root a single RAO in pool to avoid any catestrophic division by zero.
68-
SubnetAlphaIn::<T>::insert(netuid, 1);
71+
SubnetAlphaIn::<T>::insert(netuid, 1_000_000_000);
6972
SubnetMechanism::<T>::insert(netuid, 0); // Set to zero mechanism.
7073
TokenSymbol::<T>::insert(netuid, Pallet::<T>::get_symbol_for_subnet(0));
7174
continue;

0 commit comments

Comments
 (0)