From e4d802fe741cd0c6b2615c356f2a01436d292e14 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Wed, 8 Oct 2025 15:01:14 -0300 Subject: [PATCH 1/5] make crowdloan finalizable when cap is reached but before end --- pallets/crowdloan/src/lib.rs | 6 ++-- pallets/crowdloan/src/tests.rs | 51 ---------------------------------- 2 files changed, 2 insertions(+), 55 deletions(-) diff --git a/pallets/crowdloan/src/lib.rs b/pallets/crowdloan/src/lib.rs index 3f5449a49c..b951a3ea2e 100644 --- a/pallets/crowdloan/src/lib.rs +++ b/pallets/crowdloan/src/lib.rs @@ -565,14 +565,12 @@ pub mod pallet { #[pallet::compact] crowdloan_id: CrowdloanId, ) -> DispatchResult { let who = ensure_signed(origin)?; - let now = frame_system::Pallet::::block_number(); let mut crowdloan = Self::ensure_crowdloan_exists(crowdloan_id)?; - // Ensure the origin is the creator of the crowdloan and the crowdloan has ended, - // raised the cap and is not finalized. + // Ensure the origin is the creator of the crowdloan and the crowdloan has raised the cap + // and is not finalized. ensure!(who == crowdloan.creator, Error::::InvalidOrigin); - ensure!(now >= crowdloan.end, Error::::ContributionPeriodNotEnded); ensure!(crowdloan.raised == crowdloan.cap, Error::::CapNotRaised); ensure!(!crowdloan.finalized, Error::::AlreadyFinalized); diff --git a/pallets/crowdloan/src/tests.rs b/pallets/crowdloan/src/tests.rs index 1e03854b1f..95aa1dfc48 100644 --- a/pallets/crowdloan/src/tests.rs +++ b/pallets/crowdloan/src/tests.rs @@ -1147,9 +1147,6 @@ fn test_finalize_succeeds() { amount )); - // run some more blocks past the end of the contribution period - run_to_block(60); - // finalize the crowdloan assert_ok!(Crowdloan::finalize( RuntimeOrigin::signed(creator), @@ -1340,54 +1337,6 @@ fn test_finalize_fails_if_not_creator_origin() { }); } -#[test] -fn test_finalize_fails_if_crowdloan_has_not_ended() { - TestState::default() - .with_balance(U256::from(1), 100) - .with_balance(U256::from(2), 100) - .build_and_execute(|| { - // create a crowdloan - let creator: AccountOf = U256::from(1); - let deposit: BalanceOf = 50; - let min_contribution: BalanceOf = 10; - let cap: BalanceOf = 100; - let end: BlockNumberFor = 50; - - assert_ok!(Crowdloan::create( - RuntimeOrigin::signed(creator), - deposit, - min_contribution, - cap, - end, - Some(noop_call()), - None, - )); - - // run some blocks - run_to_block(10); - - // some contribution - let crowdloan_id: CrowdloanId = 0; - let contributor: AccountOf = U256::from(2); - let amount: BalanceOf = 50; - - assert_ok!(Crowdloan::contribute( - RuntimeOrigin::signed(contributor), - crowdloan_id, - amount - )); - - // run some more blocks before end of contribution period - run_to_block(10); - - // try to finalize - assert_err!( - Crowdloan::finalize(RuntimeOrigin::signed(creator), crowdloan_id), - pallet_crowdloan::Error::::ContributionPeriodNotEnded - ); - }); -} - #[test] fn test_finalize_fails_if_crowdloan_cap_is_not_raised() { TestState::default() From cef1fccf4c2696918addc881f7cba1c187031bde Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Wed, 8 Oct 2025 15:05:22 -0300 Subject: [PATCH 2/5] make crowdloan refund before the end possible --- pallets/crowdloan/src/lib.rs | 8 +++---- pallets/crowdloan/src/tests.rs | 39 +++------------------------------- 2 files changed, 6 insertions(+), 41 deletions(-) diff --git a/pallets/crowdloan/src/lib.rs b/pallets/crowdloan/src/lib.rs index b951a3ea2e..b4bebd9cbe 100644 --- a/pallets/crowdloan/src/lib.rs +++ b/pallets/crowdloan/src/lib.rs @@ -547,7 +547,7 @@ pub mod pallet { Ok(()) } - /// Finalize a successful crowdloan. + /// Finalize crowdloan that has reached the cap. /// /// The call will transfer the raised amount to the target address if it was provided when the crowdloan was created /// and dispatch the call that was provided using the creator origin. The CurrentCrowdloanId will be set to the @@ -619,7 +619,7 @@ pub mod pallet { Ok(()) } - /// Refund a failed crowdloan. + /// Refund a crowdloan that has not reached the cap and has ended. /// /// The call will try to refund all contributors (excluding the creator) up to the limit defined by the `RefundContributorsLimit`. /// If the limit is reached, the call will stop and the crowdloan will be marked as partially refunded. @@ -635,13 +635,11 @@ pub mod pallet { origin: OriginFor, #[pallet::compact] crowdloan_id: CrowdloanId, ) -> DispatchResultWithPostInfo { - let now = frame_system::Pallet::::block_number(); ensure_signed(origin)?; let mut crowdloan = Self::ensure_crowdloan_exists(crowdloan_id)?; - // Ensure the crowdloan has ended and is not finalized - ensure!(now >= crowdloan.end, Error::::ContributionPeriodNotEnded); + // Ensure the crowdloan is not finalized ensure!(!crowdloan.finalized, Error::::AlreadyFinalized); let mut refunded_contributors: Vec = vec![]; diff --git a/pallets/crowdloan/src/tests.rs b/pallets/crowdloan/src/tests.rs index 95aa1dfc48..bbc2c64795 100644 --- a/pallets/crowdloan/src/tests.rs +++ b/pallets/crowdloan/src/tests.rs @@ -1534,8 +1534,8 @@ fn test_refund_succeeds() { .is_some_and(|c| c.contributors_count == 7) ); - // run some more blocks past the end of the contribution period - run_to_block(60); + // run some more blocks before the end of the contribution period + run_to_block(20); // first round of refund assert_ok!(Crowdloan::refund( @@ -1563,7 +1563,7 @@ fn test_refund_succeeds() { pallet_crowdloan::Event::::PartiallyRefunded { crowdloan_id }.into() ); - // run some more blocks + // run some more blocks past the end of the contribution period run_to_block(70); // second round of refund @@ -1649,39 +1649,6 @@ fn test_refund_fails_if_crowdloan_does_not_exist() { }); } -#[test] -fn test_refund_fails_if_crowdloan_has_not_ended() { - TestState::default() - .with_balance(U256::from(1), 100) - .build_and_execute(|| { - // create a crowdloan - let creator: AccountOf = U256::from(1); - let initial_deposit: BalanceOf = 50; - let min_contribution: BalanceOf = 10; - let cap: BalanceOf = 300; - let end: BlockNumberFor = 50; - assert_ok!(Crowdloan::create( - RuntimeOrigin::signed(creator), - initial_deposit, - min_contribution, - cap, - end, - Some(noop_call()), - None, - )); - - // run some blocks - run_to_block(10); - - // try to refund - let crowdloan_id: CrowdloanId = 0; - assert_err!( - Crowdloan::refund(RuntimeOrigin::signed(creator), crowdloan_id), - pallet_crowdloan::Error::::ContributionPeriodNotEnded - ); - }); -} - #[test] fn test_dissolve_succeeds() { TestState::default() From 0736b0baa9a04c2b6332a434ca4b905df73f7832 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Wed, 8 Oct 2025 15:08:41 -0300 Subject: [PATCH 3/5] fix comment --- pallets/crowdloan/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/crowdloan/src/lib.rs b/pallets/crowdloan/src/lib.rs index b4bebd9cbe..aa3d4950bc 100644 --- a/pallets/crowdloan/src/lib.rs +++ b/pallets/crowdloan/src/lib.rs @@ -619,7 +619,7 @@ pub mod pallet { Ok(()) } - /// Refund a crowdloan that has not reached the cap and has ended. + /// Refund contributors of a non-finalized crowdloan. /// /// The call will try to refund all contributors (excluding the creator) up to the limit defined by the `RefundContributorsLimit`. /// If the limit is reached, the call will stop and the crowdloan will be marked as partially refunded. From 7ccea37956a8cfcb3089e36d862d0f8d56fc6c2f Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Wed, 8 Oct 2025 15:40:24 -0300 Subject: [PATCH 4/5] bump spec version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 220c5354bb..293de80de8 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -223,7 +223,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 326, + spec_version: 328, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 9cf797fbce8a76f55aa027e120f824a79a8a63e1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 8 Oct 2025 23:04:10 +0000 Subject: [PATCH 5/5] auto-update benchmark weights --- pallets/admin-utils/src/lib.rs | 2 +- pallets/subtensor/src/macros/dispatches.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index b794756995..a18150ec86 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -731,7 +731,7 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the target registrations per interval. #[pallet::call_index(21)] - #[pallet::weight(Weight::from_parts(44_320_000, 0) + #[pallet::weight(Weight::from_parts(25_980_000, 0) .saturating_add(::DbWeight::get().reads(3_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_target_registrations_per_interval( diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index d16b93e320..839cbfeac7 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -1058,7 +1058,7 @@ mod dispatches { /// The extrinsic for user to change its hotkey in subnet or all subnets. #[pallet::call_index(70)] #[pallet::weight((Weight::from_parts(275_300_000, 0) - .saturating_add(T::DbWeight::get().reads(47)) + .saturating_add(T::DbWeight::get().reads(49_u64)) .saturating_add(T::DbWeight::get().writes(37)), DispatchClass::Normal, Pays::No))] pub fn swap_hotkey( origin: OriginFor, @@ -2293,8 +2293,8 @@ mod dispatches { /// - The hotkey account to designate as the autostake destination. #[pallet::call_index(114)] #[pallet::weight((Weight::from_parts(29_930_000, 0) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)), DispatchClass::Normal, Pays::No))] pub fn set_coldkey_auto_stake_hotkey( origin: T::RuntimeOrigin, netuid: NetUid,