Skip to content

Commit 07e3f1e

Browse files
committed
Merge branch 'devnet-ready' into feat/global-subsidies
2 parents 95e1af9 + 4a01966 commit 07e3f1e

File tree

33 files changed

+126
-383
lines changed

33 files changed

+126
-383
lines changed

evm-tests/src/contracts/subnet.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -663,24 +663,6 @@ export const ISubnetABI = [
663663
stateMutability: "payable",
664664
type: "function",
665665
},
666-
{
667-
inputs: [
668-
{
669-
internalType: "uint16",
670-
name: "netuid",
671-
type: "uint16",
672-
},
673-
{
674-
internalType: "uint16",
675-
name: "maxWeightLimit",
676-
type: "uint16",
677-
},
678-
],
679-
name: "setMaxWeightLimit",
680-
outputs: [],
681-
stateMutability: "payable",
682-
type: "function",
683-
},
684666
{
685667
inputs: [
686668
{

evm-tests/test/subnet.precompile.hyperparameter.test.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,25 +208,17 @@ describe("Test the Subnet precompile contract", () => {
208208
assert.equal(valueFromContract, onchainValue);
209209
})
210210

211-
it("Can set maxWeightLimit parameter", async () => {
211+
it("Returns constant maxWeightLimit", async () => {
212212

213213
const totalNetwork = await api.query.SubtensorModule.TotalNetworks.getValue()
214214
const contract = new ethers.Contract(ISUBNET_ADDRESS, ISubnetABI, wallet);
215215
const netuid = totalNetwork - 1;
216216

217-
const newValue = 106;
218-
const tx = await contract.setMaxWeightLimit(netuid, newValue);
219-
await tx.wait();
220-
221-
let onchainValue = await api.query.SubtensorModule.MaxWeightsLimit.getValue(netuid)
222-
223-
224-
let valueFromContract = Number(
217+
const valueFromContract = Number(
225218
await contract.getMaxWeightLimit(netuid)
226219
);
227220

228-
assert.equal(valueFromContract, newValue)
229-
assert.equal(valueFromContract, onchainValue);
221+
assert.equal(valueFromContract, 0xFFFF)
230222
})
231223

232224
it("Can set immunityPeriod parameter", async () => {

hyperparameters.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
```rust
33
DefaultTake: u16 = 11_796; // 18% honest number.
44
TxRateLimit: u64 = 1; // [1 @ 64,888]
5+
MaxWeightsLimit: u16 = u16::MAX; // constant limit
56
```
67

78
### netuid 1 (text_prompting)
@@ -13,7 +14,6 @@ MaxAllowedUids: u16 = 1024;
1314
Issuance: u64 = 0;
1415
MinAllowedWeights: u16 = 8;
1516
EmissionValue: u64 = 142_223_000;
16-
MaxWeightsLimit: 455; // 455/2^16 = 0.0069
1717
ValidatorBatchSize: u16 = 1;
1818
ValidatorSequenceLen: u16 = 2048; // 2048
1919
ValidatorEpochLen: u16 = 100;
@@ -54,7 +54,6 @@ MaxAllowedUids: u16 = 4096;
5454
Issuance: u64 = 0;
5555
MinAllowedWeights: u16 = 50;
5656
EmissionValue: u64 = 857_777_000;
57-
MaxWeightsLimit: u16 = 655; // 655/2^16 = 0.01 [655 @ 7,160]
5857
ValidatorBatchSize: u16 = 32; // 32
5958
ValidatorSequenceLen: u16 = 256; // 256
6059
ValidatorEpochLen: u16 = 250; // [250 @ 7,161]

pallets/admin-utils/src/benchmarking.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -292,19 +292,6 @@ mod benchmarks {
292292
_(RawOrigin::Root, 1u16.into()/*netuid*/, 100u16/*immunity_period*/)/*sudo_set_immunity_period*/;
293293
}
294294

295-
#[benchmark]
296-
fn sudo_set_max_weight_limit() {
297-
// disable admin freeze window
298-
pallet_subtensor::Pallet::<T>::set_admin_freeze_window(0);
299-
pallet_subtensor::Pallet::<T>::init_new_network(
300-
1u16.into(), /*netuid*/
301-
1u16, /*tempo*/
302-
);
303-
304-
#[extrinsic_call]
305-
_(RawOrigin::Root, 1u16.into()/*netuid*/, 100u16/*max_weight_limit*/)/*sudo_set_max_weight_limit*/;
306-
}
307-
308295
#[benchmark]
309296
fn sudo_set_max_registrations_per_block() {
310297
// disable admin freeze window

pallets/admin-utils/src/lib.rs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -426,40 +426,6 @@ pub mod pallet {
426426
Ok(())
427427
}
428428

429-
/// The extrinsic sets the adjustment beta for a subnet.
430-
/// It is only callable by the root account or subnet owner.
431-
/// The extrinsic will call the Subtensor pallet to set the adjustment beta.
432-
#[pallet::call_index(12)]
433-
#[pallet::weight(Weight::from_parts(26_890_000, 0)
434-
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(3_u64))
435-
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)))]
436-
pub fn sudo_set_max_weight_limit(
437-
origin: OriginFor<T>,
438-
netuid: NetUid,
439-
max_weight_limit: u16,
440-
) -> DispatchResult {
441-
let maybe_owner = pallet_subtensor::Pallet::<T>::ensure_sn_owner_or_root_with_limits(
442-
origin,
443-
netuid,
444-
&[Hyperparameter::MaxWeightLimit.into()],
445-
)?;
446-
447-
ensure!(
448-
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
449-
Error::<T>::SubnetDoesNotExist
450-
);
451-
pallet_subtensor::Pallet::<T>::set_max_weight_limit(netuid, max_weight_limit);
452-
pallet_subtensor::Pallet::<T>::record_owner_rl(
453-
maybe_owner,
454-
netuid,
455-
&[Hyperparameter::MaxWeightLimit.into()],
456-
);
457-
log::debug!(
458-
"MaxWeightLimitSet( netuid: {netuid:?} max_weight_limit: {max_weight_limit:?} ) "
459-
);
460-
Ok(())
461-
}
462-
463429
/// The extrinsic sets the immunity period for a subnet.
464430
/// It is only callable by the root account or subnet owner.
465431
/// The extrinsic will call the Subtensor pallet to set the immunity period.
@@ -1252,7 +1218,7 @@ pub mod pallet {
12521218
/// The extrinsic will call the Subtensor pallet to set the minimum delegate take.
12531219
#[pallet::call_index(46)]
12541220
#[pallet::weight((
1255-
Weight::from_parts(5_000_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)),
1221+
Weight::from_parts(7_885_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)),
12561222
DispatchClass::Operational,
12571223
Pays::Yes
12581224
))]
@@ -1999,7 +1965,7 @@ pub mod pallet {
19991965
/// Only callable by root.
20001966
#[pallet::call_index(74)]
20011967
#[pallet::weight((
2002-
Weight::from_parts(5_771_000, 0)
1968+
Weight::from_parts(9_418_000, 0)
20031969
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(0_u64))
20041970
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)),
20051971
DispatchClass::Operational

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ pub type UncheckedExtrinsic = TestXt<RuntimeCall, ()>;
7777
parameter_types! {
7878
pub const InitialMinAllowedWeights: u16 = 0;
7979
pub const InitialEmissionValue: u16 = 0;
80-
pub const InitialMaxWeightsLimit: u16 = u16::MAX;
8180
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::with_sensible_defaults(
8281
Weight::from_parts(2_000_000_000_000, u64::MAX),
8382
Perbill::from_percent(75),
@@ -162,7 +161,6 @@ impl pallet_subtensor::Config for Test {
162161
type Scheduler = Scheduler;
163162
type InitialMinAllowedWeights = InitialMinAllowedWeights;
164163
type InitialEmissionValue = InitialEmissionValue;
165-
type InitialMaxWeightsLimit = InitialMaxWeightsLimit;
166164
type InitialTempo = InitialTempo;
167165
type InitialDifficulty = InitialDifficulty;
168166
type InitialAdjustmentInterval = InitialAdjustmentInterval;

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -391,39 +391,6 @@ fn test_sudo_subnet_owner_cut() {
391391
});
392392
}
393393

394-
#[test]
395-
fn test_sudo_set_max_weight_limit() {
396-
new_test_ext().execute_with(|| {
397-
let netuid = NetUid::from(1);
398-
let to_be_set: u16 = 10;
399-
add_network(netuid, 10);
400-
let init_value: u16 = SubtensorModule::get_max_weight_limit(netuid);
401-
assert_eq!(
402-
AdminUtils::sudo_set_max_weight_limit(
403-
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
404-
netuid,
405-
to_be_set
406-
),
407-
Err(DispatchError::BadOrigin)
408-
);
409-
assert_eq!(
410-
AdminUtils::sudo_set_max_weight_limit(
411-
<<Test as Config>::RuntimeOrigin>::root(),
412-
netuid.next(),
413-
to_be_set
414-
),
415-
Err(Error::<Test>::SubnetDoesNotExist.into())
416-
);
417-
assert_eq!(SubtensorModule::get_max_weight_limit(netuid), init_value);
418-
assert_ok!(AdminUtils::sudo_set_max_weight_limit(
419-
<<Test as Config>::RuntimeOrigin>::root(),
420-
netuid,
421-
to_be_set
422-
));
423-
assert_eq!(SubtensorModule::get_max_weight_limit(netuid), to_be_set);
424-
});
425-
}
426-
427394
#[test]
428395
fn test_sudo_set_issuance() {
429396
new_test_ext().execute_with(|| {

pallets/crowdloan/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,16 @@ pub mod pallet {
638638
origin: OriginFor<T>,
639639
#[pallet::compact] crowdloan_id: CrowdloanId,
640640
) -> DispatchResultWithPostInfo {
641-
ensure_signed(origin)?;
641+
let who = ensure_signed(origin)?;
642642

643643
let mut crowdloan = Self::ensure_crowdloan_exists(crowdloan_id)?;
644644

645645
// Ensure the crowdloan is not finalized
646646
ensure!(!crowdloan.finalized, Error::<T>::AlreadyFinalized);
647647

648+
// Only the creator can refund the crowdloan
649+
ensure!(who == crowdloan.creator, Error::<T>::InvalidOrigin);
650+
648651
let mut refunded_contributors: Vec<T::AccountId> = vec![];
649652
let mut refund_count = 0;
650653

pallets/crowdloan/src/tests.rs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,20 +1618,47 @@ fn test_refund_succeeds() {
16181618
}
16191619

16201620
#[test]
1621-
fn test_refund_fails_if_bad_origin() {
1622-
TestState::default().build_and_execute(|| {
1623-
let crowdloan_id: CrowdloanId = 0;
1621+
fn test_refund_fails_if_bad_or_invalid_origin() {
1622+
TestState::default()
1623+
.with_balance(U256::from(1), 100)
1624+
.build_and_execute(|| {
1625+
// create a crowdloan
1626+
let crowdloan_id: CrowdloanId = 0;
1627+
let creator: AccountOf<Test> = U256::from(1);
1628+
let initial_deposit: BalanceOf<Test> = 50;
1629+
let min_contribution: BalanceOf<Test> = 10;
1630+
let cap: BalanceOf<Test> = 300;
1631+
let end: BlockNumberFor<Test> = 50;
1632+
assert_ok!(Crowdloan::create(
1633+
RuntimeOrigin::signed(creator),
1634+
initial_deposit,
1635+
min_contribution,
1636+
cap,
1637+
end,
1638+
Some(noop_call()),
1639+
None,
1640+
));
16241641

1625-
assert_err!(
1626-
Crowdloan::refund(RuntimeOrigin::none(), crowdloan_id),
1627-
DispatchError::BadOrigin
1628-
);
1642+
assert_err!(
1643+
Crowdloan::refund(RuntimeOrigin::none(), crowdloan_id),
1644+
DispatchError::BadOrigin
1645+
);
16291646

1630-
assert_err!(
1631-
Crowdloan::refund(RuntimeOrigin::root(), crowdloan_id),
1632-
DispatchError::BadOrigin
1633-
);
1634-
});
1647+
assert_err!(
1648+
Crowdloan::refund(RuntimeOrigin::root(), crowdloan_id),
1649+
DispatchError::BadOrigin
1650+
);
1651+
1652+
// run some blocks
1653+
run_to_block(60);
1654+
1655+
// try to refund
1656+
let unknown_contributor: AccountOf<Test> = U256::from(2);
1657+
assert_err!(
1658+
Crowdloan::refund(RuntimeOrigin::signed(unknown_contributor), crowdloan_id),
1659+
pallet_crowdloan::Error::<Test>::InvalidOrigin,
1660+
);
1661+
});
16351662
}
16361663

16371664
#[test]

pallets/subtensor/src/coinbase/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pub mod block_step;
44
pub mod reveal_commits;
55
pub mod root;
66
pub mod run_coinbase;
7+
pub mod subnet_emissions;

0 commit comments

Comments
 (0)