@@ -156,17 +156,12 @@ impl<T: Config> Pallet<T> {
156
156
157
157
if crowdloan. contributors_count < T :: MaxContributors :: get ( ) {
158
158
// We have less contributors than the max allowed, so we need to refund the difference
159
- let k = crowdloan. contributors_count . into ( ) ;
160
- Ok ( Some (
161
- Weight :: from_parts ( 301_560_714 , 10079 )
162
- . saturating_add ( Weight :: from_parts ( 26_884_006 , 0 ) . saturating_mul ( k) )
163
- . saturating_add ( T :: DbWeight :: get ( ) . reads ( 41_u64 ) )
164
- . saturating_add ( T :: DbWeight :: get ( ) . reads ( 2_u64 . saturating_mul ( k) ) )
165
- . saturating_add ( T :: DbWeight :: get ( ) . writes ( 55_u64 ) )
166
- . saturating_add ( T :: DbWeight :: get ( ) . writes ( 2_u64 . saturating_mul ( k) ) )
167
- . saturating_add ( Weight :: from_parts ( 0 , 2579 ) . saturating_mul ( k) ) ,
159
+ Ok (
160
+ Some ( SubnetLeasingWeightInfo :: < T > :: do_register_leased_network (
161
+ crowdloan. contributors_count ,
162
+ ) )
163
+ . into ( ) ,
168
164
)
169
- . into ( ) )
170
165
} else {
171
166
// We have the max number of contributors, so we don't need to refund anything
172
167
Ok ( ( ) . into ( ) )
@@ -224,16 +219,9 @@ impl<T: Config> Pallet<T> {
224
219
225
220
if clear_result. unique < T :: MaxContributors :: get ( ) {
226
221
// We have cleared less than the max number of shareholders, so we need to refund the difference
227
- let k = clear_result. unique . into ( ) ;
228
- Ok ( Some (
229
- Weight :: from_parts ( 56_635_122 , 6148 )
230
- . saturating_add ( Weight :: from_parts ( 912_993 , 0 ) . saturating_mul ( k) )
231
- . saturating_add ( T :: DbWeight :: get ( ) . reads ( 4_u64 ) )
232
- . saturating_add ( T :: DbWeight :: get ( ) . reads ( ( 1_u64 ) . saturating_mul ( k) ) )
233
- . saturating_add ( T :: DbWeight :: get ( ) . writes ( 6_u64 ) )
234
- . saturating_add ( T :: DbWeight :: get ( ) . writes ( ( 1_u64 ) . saturating_mul ( k) ) )
235
- . saturating_add ( Weight :: from_parts ( 0 , 2529 ) . saturating_mul ( k) ) ,
236
- )
222
+ Ok ( Some ( SubnetLeasingWeightInfo :: < T > :: do_terminate_lease (
223
+ clear_result. unique ,
224
+ ) )
237
225
. into ( ) )
238
226
} else {
239
227
// We have cleared the max number of shareholders, so we don't need to refund anything
@@ -248,12 +236,11 @@ impl<T: Config> Pallet<T> {
248
236
/// and if not enough liquidity is available, it will accumulate the dividends for later distribution.
249
237
pub fn distribute_leased_network_dividends ( lease_id : LeaseId , owner_cut_alpha : u64 ) {
250
238
// Ensure the lease exists
251
- let lease = match SubnetLeases :: < T > :: get ( lease_id) {
252
- Some ( lease) => lease,
253
- None => {
254
- log:: debug!( "Lease {lease_id} doesn't exists so we can't distribute dividends" ) ;
255
- return ;
256
- }
239
+ let lease = if let Some ( lease) = SubnetLeases :: < T > :: get ( lease_id) {
240
+ lease
241
+ } else {
242
+ log:: debug!( "Lease {lease_id} doesn't exists so we can't distribute dividends" ) ;
243
+ return ;
257
244
} ;
258
245
259
246
// Ensure the lease has not ended
@@ -380,3 +367,27 @@ impl<T: Config> Pallet<T> {
380
367
Ok ( ( crowdloan_id, crowdloan) )
381
368
}
382
369
}
370
+
371
+ /// Weight functions needed for subnet leasing.
372
+ pub struct SubnetLeasingWeightInfo < T > ( PhantomData < T > ) ;
373
+ impl < T : frame_system:: Config > SubnetLeasingWeightInfo < T > {
374
+ pub fn do_register_leased_network ( k : u32 ) -> Weight {
375
+ Weight :: from_parts ( 301_560_714 , 10079 )
376
+ . saturating_add ( Weight :: from_parts ( 26_884_006 , 0 ) . saturating_mul ( k. into ( ) ) )
377
+ . saturating_add ( T :: DbWeight :: get ( ) . reads ( 41_u64 ) )
378
+ . saturating_add ( T :: DbWeight :: get ( ) . reads ( 2_u64 . saturating_mul ( k. into ( ) ) ) )
379
+ . saturating_add ( T :: DbWeight :: get ( ) . writes ( 55_u64 ) )
380
+ . saturating_add ( T :: DbWeight :: get ( ) . writes ( 2_u64 . saturating_mul ( k. into ( ) ) ) )
381
+ . saturating_add ( Weight :: from_parts ( 0 , 2579 ) . saturating_mul ( k. into ( ) ) )
382
+ }
383
+
384
+ pub fn do_terminate_lease ( k : u32 ) -> Weight {
385
+ Weight :: from_parts ( 56_635_122 , 6148 )
386
+ . saturating_add ( Weight :: from_parts ( 912_993 , 0 ) . saturating_mul ( k. into ( ) ) )
387
+ . saturating_add ( T :: DbWeight :: get ( ) . reads ( 4_u64 ) )
388
+ . saturating_add ( T :: DbWeight :: get ( ) . reads ( ( 1_u64 ) . saturating_mul ( k. into ( ) ) ) )
389
+ . saturating_add ( T :: DbWeight :: get ( ) . writes ( 6_u64 ) )
390
+ . saturating_add ( T :: DbWeight :: get ( ) . writes ( ( 1_u64 ) . saturating_mul ( k. into ( ) ) ) )
391
+ . saturating_add ( Weight :: from_parts ( 0 , 2529 ) . saturating_mul ( k. into ( ) ) )
392
+ }
393
+ }
0 commit comments