Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion evm-tests/get-metadata.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rm -rf .papi
npx papi add devnet -w ws://localhost:9944
npx -y polkadot-api add devnet -w ws://localhost:9944

15 changes: 8 additions & 7 deletions evm-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@
"license": "ISC",
"dependencies": {
"@polkadot-api/descriptors": "file:.papi/descriptors",
"@polkadot-labs/hdkd": "^0.0.10",
"@polkadot-labs/hdkd-helpers": "^0.0.11",
"@polkadot/api": "15.1.1",
"@polkadot-labs/hdkd": "^0.0.23",
"@polkadot-labs/hdkd-helpers": "^0.0.23",
"@polkadot/api": "^16.4.6",
"@types/mocha": "^10.0.10",
"crypto": "^1.0.1",
"dotenv": "16.4.7",
"dotenv": "17.2.1",
"ethers": "^6.13.5",
"mocha": "^11.1.0",
"polkadot-api": "^1.9.5",
"rxjs": "^7.8.2",
"scale-ts": "^1.6.1",
"viem": "2.23.4",
"ws": "^8.18.2"
},
"devDependencies": {
"@types/bun": "^1.1.13",
"@types/chai": "^5.0.1",
"@types/node": "^22.18.0",
"assert": "^2.1.0",
"chai": "^5.2.0",
"chai": "^6.0.1",
"prettier": "^3.3.3",
"ts-node": "^10.9.2",
"typescript": "^5.7.2",
"vite": "^5.4.8"
"vite": "^7.1.4"
}
}
3 changes: 0 additions & 3 deletions evm-tests/run-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ fi

cd evm-tests

# required for papi in get-metadata.sh, but we cannot run yarn before papi as it adds the descriptors to the package.json which won't resolve
npm i -g polkadot-api

bash get-metadata.sh

sleep 5
Expand Down
1,071 changes: 527 additions & 544 deletions evm-tests/yarn.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pallets/admin-utils/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ mod benchmarks {
);

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

#[benchmark]
Expand Down
30 changes: 24 additions & 6 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ pub mod pallet {
BondsMovingAverageMaxReached,
/// Only root can set negative sigmoid steepness values
NegativeSigmoidSteepness,
/// Value not in allowed bounds.
ValueNotInBounds,
}
/// Enum for specifying the type of precompile operation.
#[derive(
Expand Down Expand Up @@ -654,7 +656,7 @@ pub mod pallet {
}

/// The extrinsic sets the minimum burn for a subnet.
/// It is only callable by the root account.
/// It is only callable by root and subnet owner.
/// The extrinsic will call the Subtensor pallet to set the minimum burn.
#[pallet::call_index(22)]
#[pallet::weight(Weight::from_parts(15_440_000, 0)
Expand All @@ -665,19 +667,27 @@ pub mod pallet {
netuid: NetUid,
min_burn: TaoCurrency,
) -> DispatchResult {
ensure_root(origin)?;

pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin.clone(), netuid)?;
ensure!(
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
Error::<T>::SubnetDoesNotExist
);
ensure!(
min_burn < T::MinBurnUpperBound::get(),
Error::<T>::ValueNotInBounds
);
// Min burn must be less than max burn
ensure!(
min_burn < pallet_subtensor::Pallet::<T>::get_max_burn(netuid),
Error::<T>::ValueNotInBounds
);
pallet_subtensor::Pallet::<T>::set_min_burn(netuid, min_burn);
log::debug!("MinBurnSet( netuid: {netuid:?} min_burn: {min_burn:?} ) ");
Ok(())
}

/// The extrinsic sets the maximum burn for a subnet.
/// It is only callable by the root account or subnet owner.
/// It is only callable by root and subnet owner.
/// The extrinsic will call the Subtensor pallet to set the maximum burn.
#[pallet::call_index(23)]
#[pallet::weight(Weight::from_parts(15_940_000, 0)
Expand All @@ -688,12 +698,20 @@ pub mod pallet {
netuid: NetUid,
max_burn: TaoCurrency,
) -> DispatchResult {
ensure_root(origin)?;

pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin.clone(), netuid)?;
ensure!(
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
Error::<T>::SubnetDoesNotExist
);
ensure!(
max_burn > T::MaxBurnLowerBound::get(),
Error::<T>::ValueNotInBounds
);
// Max burn must be greater than min burn
ensure!(
max_burn > pallet_subtensor::Pallet::<T>::get_min_burn(netuid),
Error::<T>::ValueNotInBounds
);
pallet_subtensor::Pallet::<T>::set_max_burn(netuid, max_burn);
log::debug!("MaxBurnSet( netuid: {netuid:?} max_burn: {max_burn:?} ) ");
Ok(())
Expand Down
6 changes: 5 additions & 1 deletion pallets/admin-utils/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use sp_runtime::{
};
use sp_std::cmp::Ordering;
use sp_weights::Weight;
use subtensor_runtime_common::NetUid;
use subtensor_runtime_common::{NetUid, TaoCurrency};

type Block = frame_system::mocking::MockBlock<Test>;
// Configure a mock runtime to test the pallet.
Expand Down Expand Up @@ -110,6 +110,8 @@ parameter_types! {
pub const InitialBurn: u64 = 0;
pub const InitialMinBurn: u64 = 500_000;
pub const InitialMaxBurn: u64 = 1_000_000_000;
pub const MinBurnUpperBound: TaoCurrency = TaoCurrency::new(1_000_000_000); // 1 TAO
pub const MaxBurnLowerBound: TaoCurrency = TaoCurrency::new(100_000_000); // 0.1 TAO
pub const InitialValidatorPruneLen: u64 = 0;
pub const InitialScalingLawPower: u16 = 50;
pub const InitialMaxAllowedValidators: u16 = 100;
Expand Down Expand Up @@ -198,6 +200,8 @@ impl pallet_subtensor::Config for Test {
type InitialBurn = InitialBurn;
type InitialMaxBurn = InitialMaxBurn;
type InitialMinBurn = InitialMinBurn;
type MinBurnUpperBound = MinBurnUpperBound;
type MaxBurnLowerBound = MaxBurnLowerBound;
type InitialRAORecycledForRegistration = InitialRAORecycledForRegistration;
type InitialSenateRequiredStakePercentage = InitialSenateRequiredStakePercentage;
type InitialNetworkImmunityPeriod = InitialNetworkImmunityPeriod;
Expand Down
118 changes: 118 additions & 0 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1951,3 +1951,121 @@ fn test_sudo_set_commit_reveal_version() {
);
});
}

#[test]
fn test_sudo_set_min_burn() {
new_test_ext().execute_with(|| {
let netuid = NetUid::from(1);
let to_be_set = TaoCurrency::from(1_000_000);
add_network(netuid, 10);
let init_value = SubtensorModule::get_min_burn(netuid);

// Simple case
assert_ok!(AdminUtils::sudo_set_min_burn(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
TaoCurrency::from(to_be_set)
));
assert_ne!(SubtensorModule::get_min_burn(netuid), init_value);
assert_eq!(SubtensorModule::get_min_burn(netuid), to_be_set);

// Unknown subnet
assert_err!(
AdminUtils::sudo_set_min_burn(
<<Test as Config>::RuntimeOrigin>::root(),
NetUid::from(42),
TaoCurrency::from(to_be_set)
),
Error::<Test>::SubnetDoesNotExist
);

// Non subnet owner
assert_err!(
AdminUtils::sudo_set_min_burn(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
netuid,
TaoCurrency::from(to_be_set)
),
DispatchError::BadOrigin
);

// Above upper bound
assert_err!(
AdminUtils::sudo_set_min_burn(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
<Test as pallet_subtensor::Config>::MinBurnUpperBound::get() + 1.into()
),
Error::<Test>::ValueNotInBounds
);

// Above max burn
assert_err!(
AdminUtils::sudo_set_min_burn(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
SubtensorModule::get_max_burn(netuid) + 1.into()
),
Error::<Test>::ValueNotInBounds
);
});
}

#[test]
fn test_sudo_set_max_burn() {
new_test_ext().execute_with(|| {
let netuid = NetUid::from(1);
let to_be_set = TaoCurrency::from(100_000_001);
add_network(netuid, 10);
let init_value = SubtensorModule::get_max_burn(netuid);

// Simple case
assert_ok!(AdminUtils::sudo_set_max_burn(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
TaoCurrency::from(to_be_set)
));
assert_ne!(SubtensorModule::get_max_burn(netuid), init_value);
assert_eq!(SubtensorModule::get_max_burn(netuid), to_be_set);

// Unknown subnet
assert_err!(
AdminUtils::sudo_set_max_burn(
<<Test as Config>::RuntimeOrigin>::root(),
NetUid::from(42),
TaoCurrency::from(to_be_set)
),
Error::<Test>::SubnetDoesNotExist
);

// Non subnet owner
assert_err!(
AdminUtils::sudo_set_max_burn(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
netuid,
TaoCurrency::from(to_be_set)
),
DispatchError::BadOrigin
);

// Below lower bound
assert_err!(
AdminUtils::sudo_set_max_burn(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
<Test as pallet_subtensor::Config>::MaxBurnLowerBound::get() - 1.into()
),
Error::<Test>::ValueNotInBounds
);

// Below min burn
assert_err!(
AdminUtils::sudo_set_max_burn(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
SubtensorModule::get_min_burn(netuid) - 1.into()
),
Error::<Test>::ValueNotInBounds
);
});
}
6 changes: 6 additions & 0 deletions pallets/subtensor/src/macros/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ mod config {
/// Initial Min Burn.
#[pallet::constant]
type InitialMinBurn: Get<u64>;
/// Min burn upper bound.
#[pallet::constant]
type MinBurnUpperBound: Get<TaoCurrency>;
/// Max burn lower bound.
#[pallet::constant]
type MaxBurnLowerBound: Get<TaoCurrency>;
/// Initial adjustment interval.
#[pallet::constant]
type InitialAdjustmentInterval: Get<u16>;
Expand Down
4 changes: 4 additions & 0 deletions pallets/subtensor/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ parameter_types! {
pub const InitialBurn: u64 = 0;
pub const InitialMinBurn: u64 = 500_000;
pub const InitialMaxBurn: u64 = 1_000_000_000;
pub const MinBurnUpperBound: TaoCurrency = TaoCurrency::new(1_000_000_000); // 1 TAO
pub const MaxBurnLowerBound: TaoCurrency = TaoCurrency::new(100_000_000); // 0.1 TAO
pub const InitialValidatorPruneLen: u64 = 0;
pub const InitialScalingLawPower: u16 = 50;
pub const InitialMaxAllowedValidators: u16 = 100;
Expand Down Expand Up @@ -429,6 +431,8 @@ impl crate::Config for Test {
type InitialBurn = InitialBurn;
type InitialMaxBurn = InitialMaxBurn;
type InitialMinBurn = InitialMinBurn;
type MinBurnUpperBound = MinBurnUpperBound;
type MaxBurnLowerBound = MaxBurnLowerBound;
type InitialRAORecycledForRegistration = InitialRAORecycledForRegistration;
type InitialSenateRequiredStakePercentage = InitialSenateRequiredStakePercentage;
type InitialNetworkImmunityPeriod = InitialNetworkImmunityPeriod;
Expand Down
4 changes: 4 additions & 0 deletions pallets/transaction-fee/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ parameter_types! {
pub const InitialBurn: u64 = 0;
pub const InitialMinBurn: u64 = 500_000;
pub const InitialMaxBurn: u64 = 1_000_000_000;
pub const MinBurnUpperBound: TaoCurrency = TaoCurrency::new(1_000_000_000); // 1 TAO
pub const MaxBurnLowerBound: TaoCurrency = TaoCurrency::new(100_000_000); // 0.1 TAO
pub const InitialValidatorPruneLen: u64 = 0;
pub const InitialScalingLawPower: u16 = 50;
pub const InitialMaxAllowedValidators: u16 = 100;
Expand Down Expand Up @@ -263,6 +265,8 @@ impl pallet_subtensor::Config for Test {
type InitialBurn = InitialBurn;
type InitialMaxBurn = InitialMaxBurn;
type InitialMinBurn = InitialMinBurn;
type MinBurnUpperBound = MinBurnUpperBound;
type MaxBurnLowerBound = MaxBurnLowerBound;
type InitialRAORecycledForRegistration = InitialRAORecycledForRegistration;
type InitialSenateRequiredStakePercentage = InitialSenateRequiredStakePercentage;
type InitialNetworkImmunityPeriod = InitialNetworkImmunityPeriod;
Expand Down
4 changes: 4 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,8 @@ parameter_types! {
pub const SubtensorInitialBurn: u64 = 100_000_000; // 0.1 tao
pub const SubtensorInitialMinBurn: u64 = 500_000; // 500k RAO
pub const SubtensorInitialMaxBurn: u64 = 100_000_000_000; // 100 tao
pub const MinBurnUpperBound: TaoCurrency = TaoCurrency::new(1_000_000_000); // 1 TAO
pub const MaxBurnLowerBound: TaoCurrency = TaoCurrency::new(100_000_000); // 0.1 TAO
pub const SubtensorInitialTxRateLimit: u64 = 1000;
pub const SubtensorInitialTxDelegateTakeRateLimit: u64 = 216000; // 30 days at 12 seconds per block
pub const SubtensorInitialTxChildKeyTakeRateLimit: u64 = INITIAL_CHILDKEY_TAKE_RATELIMIT;
Expand Down Expand Up @@ -1210,6 +1212,8 @@ impl pallet_subtensor::Config for Runtime {
type InitialBurn = SubtensorInitialBurn;
type InitialMaxBurn = SubtensorInitialMaxBurn;
type InitialMinBurn = SubtensorInitialMinBurn;
type MinBurnUpperBound = MinBurnUpperBound;
type MaxBurnLowerBound = MaxBurnLowerBound;
type InitialTxRateLimit = SubtensorInitialTxRateLimit;
type InitialTxDelegateTakeRateLimit = SubtensorInitialTxDelegateTakeRateLimit;
type InitialTxChildKeyTakeRateLimit = SubtensorInitialTxChildKeyTakeRateLimit;
Expand Down
Loading