Skip to content

Commit 79737e1

Browse files
committed
fix: apply lock cost multiplier after subnet registration
- treat missing last_lock_block as post-registration when last_lock > min_lock - add regression test for lock cost multiplier
1 parent 8f13194 commit 79737e1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

pallets/subtensor/src/coinbase/root.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,12 @@ impl<T: Config> Pallet<T> {
511511
let last_lock_block = Self::get_network_last_lock_block();
512512
let current_block = Self::get_current_block_as_u64();
513513
let lock_reduction_interval = Self::get_lock_reduction_interval();
514-
let mult: TaoCurrency = if last_lock_block == 0 { 1 } else { 2 }.into();
514+
let mult: TaoCurrency = if last_lock_block == 0 && last_lock <= min_lock {
515+
1
516+
} else {
517+
2
518+
}
519+
.into();
515520

516521
let mut lock_cost = last_lock.saturating_mul(mult).saturating_sub(
517522
last_lock

pallets/subtensor/src/tests/networks.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::migrations::migrate_network_immunity_period;
55
use crate::*;
66
use frame_support::{assert_err, assert_ok};
77
use frame_system::Config;
8+
use safe_math::SafeDiv;
89
use sp_core::U256;
910
use sp_std::collections::{btree_map::BTreeMap, vec_deque::VecDeque};
1011
use substrate_fixed::types::{I96F32, U64F64, U96F32};
@@ -1757,6 +1758,32 @@ fn test_register_subnet_high_lock_cost() {
17571758
})
17581759
}
17591760

1761+
#[test]
1762+
fn test_lock_cost_uses_multiplier_when_last_lock_block_missing() {
1763+
new_test_ext(1).execute_with(|| {
1764+
let min_lock = TaoCurrency::from(1_000);
1765+
let last_lock = TaoCurrency::from(10_000);
1766+
1767+
NetworkMinLockCost::<Test>::set(min_lock);
1768+
NetworkLastLockCost::<Test>::set(last_lock);
1769+
SubtensorModule::set_network_last_lock_block(0);
1770+
1771+
step_block(1);
1772+
1773+
let current_block = SubtensorModule::get_current_block_as_u64();
1774+
let lock_reduction_interval = SubtensorModule::get_lock_reduction_interval();
1775+
let per_block_decrement = last_lock
1776+
.to_u64()
1777+
.safe_div(lock_reduction_interval)
1778+
.saturating_mul(current_block.saturating_sub(0));
1779+
let expected = last_lock
1780+
.saturating_mul(2u64.into())
1781+
.saturating_sub(per_block_decrement.into());
1782+
1783+
assert_eq!(SubtensorModule::get_network_lock_cost(), expected);
1784+
})
1785+
}
1786+
17601787
#[test]
17611788
fn test_tempo_greater_than_weight_set_rate_limit() {
17621789
new_test_ext(1).execute_with(|| {

0 commit comments

Comments
 (0)