Skip to content

Commit abdb88b

Browse files
committed
address lints
1 parent 9bdc8c6 commit abdb88b

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pallets/utility/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ frame-system = { workspace = true, default-features = false }
2121
sp-core = { workspace = true, default-features = false }
2222
sp-io = { workspace = true, default-features = false}
2323
sp-runtime = { workspace = true, default-features = false}
24+
subtensor-macros = { workspace = true }
2425

2526
[dev-dependencies]
2627
pallet-balances = { default-features = true, workspace = true }

pallets/utility/src/lib.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ use sp_io::hashing::blake2_256;
6969
use sp_runtime::traits::{BadOrigin, Dispatchable, TrailingZeroInput};
7070
pub use weights::WeightInfo;
7171

72+
use subtensor_macros::freeze_struct;
73+
7274
pub use pallet::*;
7375

7476
#[frame_support::pallet]
@@ -133,14 +135,19 @@ pub mod pallet {
133135
/// The limit on the number of batched calls.
134136
fn batched_calls_limit() -> u32 {
135137
let allocator_limit = sp_core::MAX_POSSIBLE_ALLOCATION;
136-
let call_size =
137-
((core::mem::size_of::<<T as Config>::RuntimeCall>() as u32 + CALL_ALIGN - 1)
138-
/ CALL_ALIGN)
139-
* CALL_ALIGN;
140-
// The margin to take into account vec doubling capacity.
141-
let margin_factor = 3;
142-
143-
allocator_limit / margin_factor / call_size
138+
let size = core::mem::size_of::<<T as Config>::RuntimeCall>() as u32;
139+
140+
let align_up = size.saturating_add(CALL_ALIGN.saturating_sub(1));
141+
let call_size = align_up
142+
.checked_div(CALL_ALIGN)
143+
.unwrap_or(0)
144+
.saturating_mul(CALL_ALIGN);
145+
146+
let margin_factor: u32 = 3;
147+
148+
let after_margin = allocator_limit.checked_div(margin_factor).unwrap_or(0);
149+
150+
after_margin.checked_div(call_size).unwrap_or(0)
144151
}
145152
}
146153

@@ -184,7 +191,7 @@ pub mod pallet {
184191
/// event is deposited.
185192
#[pallet::call_index(0)]
186193
#[pallet::weight({
187-
let (dispatch_weight, dispatch_class) = Pallet::<T>::weight_and_dispatch_class(&calls);
194+
let (dispatch_weight, dispatch_class) = Pallet::<T>::weight_and_dispatch_class(calls);
188195
let dispatch_weight = dispatch_weight.saturating_add(T::WeightInfo::batch(calls.len() as u32));
189196
(dispatch_weight, dispatch_class)
190197
})]
@@ -296,7 +303,7 @@ pub mod pallet {
296303
/// - O(C) where C is the number of calls to be batched.
297304
#[pallet::call_index(2)]
298305
#[pallet::weight({
299-
let (dispatch_weight, dispatch_class) = Pallet::<T>::weight_and_dispatch_class(&calls);
306+
let (dispatch_weight, dispatch_class) = Pallet::<T>::weight_and_dispatch_class(calls);
300307
let dispatch_weight = dispatch_weight.saturating_add(T::WeightInfo::batch_all(calls.len() as u32));
301308
(dispatch_weight, dispatch_class)
302309
})]
@@ -395,7 +402,7 @@ pub mod pallet {
395402
/// - O(C) where C is the number of calls to be batched.
396403
#[pallet::call_index(4)]
397404
#[pallet::weight({
398-
let (dispatch_weight, dispatch_class) = Pallet::<T>::weight_and_dispatch_class(&calls);
405+
let (dispatch_weight, dispatch_class) = Pallet::<T>::weight_and_dispatch_class(calls);
399406
let dispatch_weight = dispatch_weight.saturating_add(T::WeightInfo::force_batch(calls.len() as u32));
400407
(dispatch_weight, dispatch_class)
401408
})]
@@ -496,6 +503,7 @@ pub mod pallet {
496503
}
497504

498505
/// A pallet identifier. These are per pallet and should be stored in a registry somewhere.
506+
#[freeze_struct("7e600c53ace0630a")]
499507
#[derive(Clone, Copy, Eq, PartialEq, Encode, Decode)]
500508
struct IndexedUtilityPalletId(u16);
501509

pallets/utility/src/tests.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type BlockNumber = u64;
3939

4040
// example module to test behaviors.
4141
#[frame_support::pallet(dev_mode)]
42+
#[allow(clippy::large_enum_variant)]
4243
pub mod example {
4344
use frame_support::{dispatch::WithPostDispatchInfo, pallet_prelude::*};
4445
use frame_system::pallet_prelude::*;
@@ -127,14 +128,14 @@ type Block = frame_system::mocking::MockBlock<Test>;
127128
frame_support::construct_runtime!(
128129
pub enum Test
129130
{
130-
System: frame_system,
131-
Timestamp: pallet_timestamp,
132-
Balances: pallet_balances,
133-
RootTesting: pallet_root_testing,
134-
Council: pallet_collective::<Instance1>,
135-
Utility: utility,
136-
Example: example,
137-
Democracy: mock_democracy,
131+
System: frame_system = 1,
132+
Timestamp: pallet_timestamp = 2,
133+
Balances: pallet_balances = 3,
134+
RootTesting: pallet_root_testing = 4,
135+
Council: pallet_collective::<Instance1> = 5,
136+
Utility: utility = 6,
137+
Example: example = 7,
138+
Democracy: mock_democracy = 8,
138139
}
139140
);
140141

@@ -174,7 +175,7 @@ parameter_types! {
174175
pub const MotionDuration: BlockNumber = MOTION_DURATION_IN_BLOCKS;
175176
pub const MaxProposals: u32 = 100;
176177
pub const MaxMembers: u32 = 100;
177-
pub MaxProposalWeight: Weight = sp_runtime::Perbill::from_percent(50) * BlockWeights::get().max_block;
178+
pub MaxProposalWeight: Weight = BlockWeights::get().max_block.saturating_div(2);
178179
}
179180

180181
pub struct MemberProposals;
@@ -255,19 +256,19 @@ use pallet_timestamp::Call as TimestampCall;
255256
pub fn new_test_ext() -> sp_io::TestExternalities {
256257
let mut t = frame_system::GenesisConfig::<Test>::default()
257258
.build_storage()
258-
.unwrap();
259+
.expect("Failed to build storage for test");
259260
pallet_balances::GenesisConfig::<Test> {
260261
balances: vec![(1, 10), (2, 10), (3, 10), (4, 10), (5, 2)],
261262
}
262263
.assimilate_storage(&mut t)
263-
.unwrap();
264+
.expect("Failed to build storage for test");
264265

265266
pallet_collective::GenesisConfig::<Test, Instance1> {
266267
members: vec![1, 2, 3],
267268
phantom: Default::default(),
268269
}
269270
.assimilate_storage(&mut t)
270-
.unwrap();
271+
.expect("Failed to build storage for test");
271272

272273
let mut ext = sp_io::TestExternalities::new(t);
273274
ext.execute_with(|| System::set_block_number(1));
@@ -688,7 +689,7 @@ fn batch_all_handles_weight_refund() {
688689
assert_err_ignore_postinfo!(result, "The cake is a lie.");
689690
assert_eq!(
690691
extract_actual_weight(&result, &info),
691-
info.weight - diff * batch_len
692+
info.weight.saturating_sub(diff.saturating_mul(batch_len))
692693
);
693694

694695
// Partial batch completion
@@ -702,7 +703,7 @@ fn batch_all_handles_weight_refund() {
702703
assert_eq!(
703704
extract_actual_weight(&result, &info),
704705
// Real weight is 2 calls at end_weight
705-
<Test as Config>::WeightInfo::batch_all(2) + end_weight * 2,
706+
<Test as Config>::WeightInfo::batch_all(2).saturating_add(end_weight.saturating_mul(2)),
706707
);
707708
});
708709
}

0 commit comments

Comments
 (0)