Skip to content

Commit 45b7b59

Browse files
authored
Merge pull request #1995 from opentensor/min_burn_allowed
Min burn allowed
2 parents 967bfbb + 4bae03f commit 45b7b59

File tree

11 files changed

+705
-563
lines changed

11 files changed

+705
-563
lines changed

.github/workflows/evm-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
uses: Swatinem/rust-cache@v2
4141

4242
- name: Set up Node.js
43-
uses: actions/setup-node@v2
43+
uses: actions/setup-node@v4
4444
with:
4545
node-version: "22"
4646

evm-tests/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,28 @@
77
"license": "ISC",
88
"dependencies": {
99
"@polkadot-api/descriptors": "file:.papi/descriptors",
10-
"@polkadot-labs/hdkd": "^0.0.10",
11-
"@polkadot-labs/hdkd-helpers": "^0.0.11",
12-
"@polkadot/api": "15.1.1",
10+
"@polkadot-labs/hdkd": "^0.0.23",
11+
"@polkadot-labs/hdkd-helpers": "^0.0.23",
12+
"@polkadot/api": "^16.4.6",
1313
"@types/mocha": "^10.0.10",
14-
"crypto": "^1.0.1",
15-
"dotenv": "16.4.7",
14+
"dotenv": "17.2.1",
1615
"ethers": "^6.13.5",
1716
"mocha": "^11.1.0",
1817
"polkadot-api": "^1.9.5",
18+
"rxjs": "^7.8.2",
1919
"scale-ts": "^1.6.1",
2020
"viem": "2.23.4",
2121
"ws": "^8.18.2"
2222
},
2323
"devDependencies": {
2424
"@types/bun": "^1.1.13",
2525
"@types/chai": "^5.0.1",
26+
"@types/node": "^22.18.0",
2627
"assert": "^2.1.0",
27-
"chai": "^5.2.0",
28+
"chai": "^6.0.1",
2829
"prettier": "^3.3.3",
2930
"ts-node": "^10.9.2",
3031
"typescript": "^5.7.2",
31-
"vite": "^5.4.8"
32+
"vite": "^7.1.4"
3233
}
3334
}

evm-tests/yarn.lock

Lines changed: 527 additions & 544 deletions
Large diffs are not rendered by default.

pallets/admin-utils/src/benchmarking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ mod benchmarks {
266266
);
267267

268268
#[extrinsic_call]
269-
_(RawOrigin::Root, 1u16.into()/*netuid*/, 10.into()/*max_burn*/)/*sudo_set_max_burn*/;
269+
_(RawOrigin::Root, 1u16.into()/*netuid*/, 2_000_000_000.into()/*max_burn*/)/*sudo_set_max_burn*/;
270270
}
271271

272272
#[benchmark]

pallets/admin-utils/src/lib.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ pub mod pallet {
107107
BondsMovingAverageMaxReached,
108108
/// Only root can set negative sigmoid steepness values
109109
NegativeSigmoidSteepness,
110+
/// Value not in allowed bounds.
111+
ValueNotInBounds,
110112
}
111113
/// Enum for specifying the type of precompile operation.
112114
#[derive(
@@ -654,46 +656,62 @@ pub mod pallet {
654656
}
655657

656658
/// The extrinsic sets the minimum burn for a subnet.
657-
/// It is only callable by the root account.
659+
/// It is only callable by root and subnet owner.
658660
/// The extrinsic will call the Subtensor pallet to set the minimum burn.
659661
#[pallet::call_index(22)]
660-
#[pallet::weight(Weight::from_parts(15_440_000, 0)
661-
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(1_u64))
662+
#[pallet::weight(Weight::from_parts(18_870_000, 0)
663+
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(2_u64))
662664
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)))]
663665
pub fn sudo_set_min_burn(
664666
origin: OriginFor<T>,
665667
netuid: NetUid,
666668
min_burn: TaoCurrency,
667669
) -> DispatchResult {
668-
ensure_root(origin)?;
669-
670+
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin.clone(), netuid)?;
670671
ensure!(
671672
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
672673
Error::<T>::SubnetDoesNotExist
673674
);
675+
ensure!(
676+
min_burn < T::MinBurnUpperBound::get(),
677+
Error::<T>::ValueNotInBounds
678+
);
679+
// Min burn must be less than max burn
680+
ensure!(
681+
min_burn < pallet_subtensor::Pallet::<T>::get_max_burn(netuid),
682+
Error::<T>::ValueNotInBounds
683+
);
674684
pallet_subtensor::Pallet::<T>::set_min_burn(netuid, min_burn);
675685
log::debug!("MinBurnSet( netuid: {netuid:?} min_burn: {min_burn:?} ) ");
676686
Ok(())
677687
}
678688

679689
/// The extrinsic sets the maximum burn for a subnet.
680-
/// It is only callable by the root account or subnet owner.
690+
/// It is only callable by root and subnet owner.
681691
/// The extrinsic will call the Subtensor pallet to set the maximum burn.
682692
#[pallet::call_index(23)]
683693
#[pallet::weight(Weight::from_parts(15_940_000, 0)
684-
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(1_u64))
694+
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(2_u64))
685695
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)))]
686696
pub fn sudo_set_max_burn(
687697
origin: OriginFor<T>,
688698
netuid: NetUid,
689699
max_burn: TaoCurrency,
690700
) -> DispatchResult {
691-
ensure_root(origin)?;
692-
701+
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin.clone(), netuid)?;
693702
ensure!(
694703
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
695704
Error::<T>::SubnetDoesNotExist
696705
);
706+
ensure!(
707+
max_burn > T::MaxBurnLowerBound::get(),
708+
Error::<T>::ValueNotInBounds
709+
);
710+
// Max burn must be greater than min burn
711+
ensure!(
712+
max_burn > pallet_subtensor::Pallet::<T>::get_min_burn(netuid),
713+
Error::<T>::ValueNotInBounds
714+
);
697715
pallet_subtensor::Pallet::<T>::set_max_burn(netuid, max_burn);
698716
log::debug!("MaxBurnSet( netuid: {netuid:?} max_burn: {max_burn:?} ) ");
699717
Ok(())

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use sp_runtime::{
1919
};
2020
use sp_std::cmp::Ordering;
2121
use sp_weights::Weight;
22-
use subtensor_runtime_common::NetUid;
22+
use subtensor_runtime_common::{NetUid, TaoCurrency};
2323

2424
type Block = frame_system::mocking::MockBlock<Test>;
2525
// Configure a mock runtime to test the pallet.
@@ -110,6 +110,8 @@ parameter_types! {
110110
pub const InitialBurn: u64 = 0;
111111
pub const InitialMinBurn: u64 = 500_000;
112112
pub const InitialMaxBurn: u64 = 1_000_000_000;
113+
pub const MinBurnUpperBound: TaoCurrency = TaoCurrency::new(1_000_000_000); // 1 TAO
114+
pub const MaxBurnLowerBound: TaoCurrency = TaoCurrency::new(100_000_000); // 0.1 TAO
113115
pub const InitialValidatorPruneLen: u64 = 0;
114116
pub const InitialScalingLawPower: u16 = 50;
115117
pub const InitialMaxAllowedValidators: u16 = 100;
@@ -198,6 +200,8 @@ impl pallet_subtensor::Config for Test {
198200
type InitialBurn = InitialBurn;
199201
type InitialMaxBurn = InitialMaxBurn;
200202
type InitialMinBurn = InitialMinBurn;
203+
type MinBurnUpperBound = MinBurnUpperBound;
204+
type MaxBurnLowerBound = MaxBurnLowerBound;
201205
type InitialRAORecycledForRegistration = InitialRAORecycledForRegistration;
202206
type InitialSenateRequiredStakePercentage = InitialSenateRequiredStakePercentage;
203207
type InitialNetworkImmunityPeriod = InitialNetworkImmunityPeriod;

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

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,3 +1951,121 @@ fn test_sudo_set_commit_reveal_version() {
19511951
);
19521952
});
19531953
}
1954+
1955+
#[test]
1956+
fn test_sudo_set_min_burn() {
1957+
new_test_ext().execute_with(|| {
1958+
let netuid = NetUid::from(1);
1959+
let to_be_set = TaoCurrency::from(1_000_000);
1960+
add_network(netuid, 10);
1961+
let init_value = SubtensorModule::get_min_burn(netuid);
1962+
1963+
// Simple case
1964+
assert_ok!(AdminUtils::sudo_set_min_burn(
1965+
<<Test as Config>::RuntimeOrigin>::root(),
1966+
netuid,
1967+
TaoCurrency::from(to_be_set)
1968+
));
1969+
assert_ne!(SubtensorModule::get_min_burn(netuid), init_value);
1970+
assert_eq!(SubtensorModule::get_min_burn(netuid), to_be_set);
1971+
1972+
// Unknown subnet
1973+
assert_err!(
1974+
AdminUtils::sudo_set_min_burn(
1975+
<<Test as Config>::RuntimeOrigin>::root(),
1976+
NetUid::from(42),
1977+
TaoCurrency::from(to_be_set)
1978+
),
1979+
Error::<Test>::SubnetDoesNotExist
1980+
);
1981+
1982+
// Non subnet owner
1983+
assert_err!(
1984+
AdminUtils::sudo_set_min_burn(
1985+
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
1986+
netuid,
1987+
TaoCurrency::from(to_be_set)
1988+
),
1989+
DispatchError::BadOrigin
1990+
);
1991+
1992+
// Above upper bound
1993+
assert_err!(
1994+
AdminUtils::sudo_set_min_burn(
1995+
<<Test as Config>::RuntimeOrigin>::root(),
1996+
netuid,
1997+
<Test as pallet_subtensor::Config>::MinBurnUpperBound::get() + 1.into()
1998+
),
1999+
Error::<Test>::ValueNotInBounds
2000+
);
2001+
2002+
// Above max burn
2003+
assert_err!(
2004+
AdminUtils::sudo_set_min_burn(
2005+
<<Test as Config>::RuntimeOrigin>::root(),
2006+
netuid,
2007+
SubtensorModule::get_max_burn(netuid) + 1.into()
2008+
),
2009+
Error::<Test>::ValueNotInBounds
2010+
);
2011+
});
2012+
}
2013+
2014+
#[test]
2015+
fn test_sudo_set_max_burn() {
2016+
new_test_ext().execute_with(|| {
2017+
let netuid = NetUid::from(1);
2018+
let to_be_set = TaoCurrency::from(100_000_001);
2019+
add_network(netuid, 10);
2020+
let init_value = SubtensorModule::get_max_burn(netuid);
2021+
2022+
// Simple case
2023+
assert_ok!(AdminUtils::sudo_set_max_burn(
2024+
<<Test as Config>::RuntimeOrigin>::root(),
2025+
netuid,
2026+
TaoCurrency::from(to_be_set)
2027+
));
2028+
assert_ne!(SubtensorModule::get_max_burn(netuid), init_value);
2029+
assert_eq!(SubtensorModule::get_max_burn(netuid), to_be_set);
2030+
2031+
// Unknown subnet
2032+
assert_err!(
2033+
AdminUtils::sudo_set_max_burn(
2034+
<<Test as Config>::RuntimeOrigin>::root(),
2035+
NetUid::from(42),
2036+
TaoCurrency::from(to_be_set)
2037+
),
2038+
Error::<Test>::SubnetDoesNotExist
2039+
);
2040+
2041+
// Non subnet owner
2042+
assert_err!(
2043+
AdminUtils::sudo_set_max_burn(
2044+
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
2045+
netuid,
2046+
TaoCurrency::from(to_be_set)
2047+
),
2048+
DispatchError::BadOrigin
2049+
);
2050+
2051+
// Below lower bound
2052+
assert_err!(
2053+
AdminUtils::sudo_set_max_burn(
2054+
<<Test as Config>::RuntimeOrigin>::root(),
2055+
netuid,
2056+
<Test as pallet_subtensor::Config>::MaxBurnLowerBound::get() - 1.into()
2057+
),
2058+
Error::<Test>::ValueNotInBounds
2059+
);
2060+
2061+
// Below min burn
2062+
assert_err!(
2063+
AdminUtils::sudo_set_max_burn(
2064+
<<Test as Config>::RuntimeOrigin>::root(),
2065+
netuid,
2066+
SubtensorModule::get_min_burn(netuid) - 1.into()
2067+
),
2068+
Error::<Test>::ValueNotInBounds
2069+
);
2070+
});
2071+
}

pallets/subtensor/src/macros/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ mod config {
9898
/// Initial Min Burn.
9999
#[pallet::constant]
100100
type InitialMinBurn: Get<u64>;
101+
/// Min burn upper bound.
102+
#[pallet::constant]
103+
type MinBurnUpperBound: Get<TaoCurrency>;
104+
/// Max burn lower bound.
105+
#[pallet::constant]
106+
type MaxBurnLowerBound: Get<TaoCurrency>;
101107
/// Initial adjustment interval.
102108
#[pallet::constant]
103109
type InitialAdjustmentInterval: Get<u16>;

pallets/subtensor/src/tests/mock.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ parameter_types! {
183183
pub const InitialBurn: u64 = 0;
184184
pub const InitialMinBurn: u64 = 500_000;
185185
pub const InitialMaxBurn: u64 = 1_000_000_000;
186+
pub const MinBurnUpperBound: TaoCurrency = TaoCurrency::new(1_000_000_000); // 1 TAO
187+
pub const MaxBurnLowerBound: TaoCurrency = TaoCurrency::new(100_000_000); // 0.1 TAO
186188
pub const InitialValidatorPruneLen: u64 = 0;
187189
pub const InitialScalingLawPower: u16 = 50;
188190
pub const InitialMaxAllowedValidators: u16 = 100;
@@ -429,6 +431,8 @@ impl crate::Config for Test {
429431
type InitialBurn = InitialBurn;
430432
type InitialMaxBurn = InitialMaxBurn;
431433
type InitialMinBurn = InitialMinBurn;
434+
type MinBurnUpperBound = MinBurnUpperBound;
435+
type MaxBurnLowerBound = MaxBurnLowerBound;
432436
type InitialRAORecycledForRegistration = InitialRAORecycledForRegistration;
433437
type InitialSenateRequiredStakePercentage = InitialSenateRequiredStakePercentage;
434438
type InitialNetworkImmunityPeriod = InitialNetworkImmunityPeriod;

pallets/transaction-fee/src/tests/mock.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ parameter_types! {
175175
pub const InitialBurn: u64 = 0;
176176
pub const InitialMinBurn: u64 = 500_000;
177177
pub const InitialMaxBurn: u64 = 1_000_000_000;
178+
pub const MinBurnUpperBound: TaoCurrency = TaoCurrency::new(1_000_000_000); // 1 TAO
179+
pub const MaxBurnLowerBound: TaoCurrency = TaoCurrency::new(100_000_000); // 0.1 TAO
178180
pub const InitialValidatorPruneLen: u64 = 0;
179181
pub const InitialScalingLawPower: u16 = 50;
180182
pub const InitialMaxAllowedValidators: u16 = 100;
@@ -263,6 +265,8 @@ impl pallet_subtensor::Config for Test {
263265
type InitialBurn = InitialBurn;
264266
type InitialMaxBurn = InitialMaxBurn;
265267
type InitialMinBurn = InitialMinBurn;
268+
type MinBurnUpperBound = MinBurnUpperBound;
269+
type MaxBurnLowerBound = MaxBurnLowerBound;
266270
type InitialRAORecycledForRegistration = InitialRAORecycledForRegistration;
267271
type InitialSenateRequiredStakePercentage = InitialSenateRequiredStakePercentage;
268272
type InitialNetworkImmunityPeriod = InitialNetworkImmunityPeriod;

0 commit comments

Comments
 (0)