Skip to content

Commit 726170b

Browse files
committed
Merge remote-tracking branch 'origin/devnet-ready' into sam-add-freeze-layout-devnet
2 parents c8016ca + 1a0d09f commit 726170b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+398
-228
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ members = [
99
resolver = "2"
1010

1111
[workspace.lints.clippy]
12+
indexing-slicing = "deny"
13+
arithmetic-side-effects = "deny"
1214
type_complexity = "allow"
15+
unwrap-used = "deny"
1316

1417
[workspace.dependencies]
1518
cargo-husky = { version = "1", default-features = false }

node/src/chain_spec/finney.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::*;
55

66
pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
77
let path: PathBuf = std::path::PathBuf::from("./snapshot.json");
8-
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
8+
let wasm_binary = WASM_BINARY.ok_or("Development wasm not available".to_string())?;
99

1010
// We mmap the file into memory first, as this is *a lot* faster than using
1111
// `serde_json::from_reader`. See https://github.com/serde-rs/json/issues/160
@@ -53,7 +53,9 @@ pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
5353
let key_account = sp_runtime::AccountId32::from(key);
5454

5555
processed_balances.push((key_account, *amount));
56-
balances_issuance += *amount;
56+
balances_issuance = balances_issuance
57+
.checked_add(*amount)
58+
.ok_or("Balances issuance overflowed".to_string())?;
5759
}
5860

5961
// Give front-ends necessary data to present to users

node/src/chain_spec/testnet.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
2020
};
2121

2222
let old_state: ColdkeyHotkeys =
23-
json::from_slice(&bytes).map_err(|e| format!("Error parsing genesis file: {}", e))?;
23+
json::from_slice(&bytes).map_err(|e| format!("Error parsing genesis file: {e}"))?;
2424

2525
let mut processed_stakes: Vec<(
2626
sp_runtime::AccountId32,
@@ -53,7 +53,9 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
5353
let key_account = sp_runtime::AccountId32::from(key);
5454

5555
processed_balances.push((key_account, *amount));
56-
balances_issuance += *amount;
56+
balances_issuance = balances_issuance
57+
.checked_add(*amount)
58+
.ok_or("Balances issuance overflowed".to_string())?;
5759
}
5860

5961
// Give front-ends necessary data to present to users

pallets/admin-utils/src/benchmarking.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Benchmarking setup
22
#![cfg(feature = "runtime-benchmarks")]
3+
#![allow(clippy::arithmetic_side_effects)]
34
use super::*;
45

56
#[allow(unused)]

pallets/admin-utils/tests/mock.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]
2+
13
use frame_support::{
24
assert_ok, derive_impl, parameter_types,
35
traits::{Everything, Hooks},

pallets/collective/src/benchmarking.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// limitations under the License.
1717

1818
//! Staking pallet benchmarking.
19+
#![allow(clippy::arithmetic_side_effects, clippy::indexing_slicing)]
1920

2021
use super::*;
2122
use crate::Pallet as Collective;
@@ -70,7 +71,7 @@ benchmarks_instance_pallet! {
7071
// Proposals should be different so that different proposal hashes are generated
7172
let proposal: T::Proposal = SystemCall::<T>::remark { remark: id_to_remark_data(i, length) }.into();
7273
Collective::<T, I>::propose(
73-
SystemOrigin::Signed(old_members.last().unwrap().clone()).into(),
74+
SystemOrigin::Signed(old_members.last().expect("m is greater than 0; old_members must have at least 1 element; qed").clone()).into(),
7475
Box::new(proposal.clone()),
7576
MAX_BYTES,
7677
TryInto::<BlockNumberFor<T>>::try_into(3u64).ok().expect("convert u64 to block number.")

pallets/collective/src/lib.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use frame_support::{
5454
use scale_info::TypeInfo;
5555
use sp_io::storage;
5656
use sp_runtime::traits::Dispatchable;
57-
use sp_runtime::{traits::Hash, RuntimeDebug};
57+
use sp_runtime::{traits::Hash, RuntimeDebug, Saturating};
5858
use sp_std::{marker::PhantomData, prelude::*, result};
5959

6060
#[cfg(test)]
@@ -120,7 +120,7 @@ impl DefaultVote for MoreThanMajorityThenPrimeDefaultVote {
120120
_no_votes: MemberCount,
121121
len: MemberCount,
122122
) -> bool {
123-
let more_than_majority = yes_votes * 2 > len;
123+
let more_than_majority = yes_votes.saturating_mul(2) > len;
124124
more_than_majority || prime_vote.unwrap_or(false)
125125
}
126126
}
@@ -547,7 +547,9 @@ pub mod pallet {
547547
Error::<T, I>::DurationLowerThanConfiguredMotionDuration
548548
);
549549

550-
let threshold = (T::GetVotingMembers::get_count() / 2) + 1;
550+
let threshold = T::GetVotingMembers::get_count()
551+
.saturating_div(2)
552+
.saturating_add(1);
551553

552554
let members = Self::members();
553555
let (proposal_len, active_proposals) =
@@ -718,10 +720,15 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
718720
})?;
719721

720722
let index = Self::proposal_count();
721-
<ProposalCount<T, I>>::mutate(|i| *i += 1);
723+
<ProposalCount<T, I>>::try_mutate(|i| {
724+
*i = i
725+
.checked_add(1)
726+
.ok_or(Error::<T, I>::TooManyActiveProposals)?;
727+
Ok::<(), Error<T, I>>(())
728+
})?;
722729
<ProposalOf<T, I>>::insert(proposal_hash, proposal);
723730
let votes = {
724-
let end = frame_system::Pallet::<T>::block_number() + duration;
731+
let end = frame_system::Pallet::<T>::block_number().saturating_add(duration);
725732
Votes {
726733
index,
727734
threshold,
@@ -864,10 +871,10 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
864871
// default voting strategy.
865872
let default = T::DefaultVote::default_vote(prime_vote, yes_votes, no_votes, seats);
866873

867-
let abstentions = seats - (yes_votes + no_votes);
874+
let abstentions = seats.saturating_sub(yes_votes.saturating_add(no_votes));
868875
match default {
869-
true => yes_votes += abstentions,
870-
false => no_votes += abstentions,
876+
true => yes_votes = yes_votes.saturating_add(abstentions),
877+
false => no_votes = no_votes.saturating_add(abstentions),
871878
}
872879
let approved = yes_votes >= voting.threshold;
873880

@@ -983,7 +990,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
983990
Voting::<T, I>::remove(proposal_hash);
984991
let num_proposals = Proposals::<T, I>::mutate(|proposals| {
985992
proposals.retain(|h| h != &proposal_hash);
986-
proposals.len() + 1 // calculate weight based on original length
993+
proposals.len().saturating_add(1) // calculate weight based on original length
987994
});
988995
num_proposals as u32
989996
}
@@ -1156,7 +1163,7 @@ impl<
11561163
type Success = ();
11571164
fn try_origin(o: O) -> Result<Self::Success, O> {
11581165
o.into().and_then(|o| match o {
1159-
RawOrigin::Members(n, m) if n * D > N * m => Ok(()),
1166+
RawOrigin::Members(n, m) if n.saturating_mul(D) > N.saturating_mul(m) => Ok(()),
11601167
r => Err(O::from(r)),
11611168
})
11621169
}
@@ -1181,7 +1188,7 @@ impl<
11811188
type Success = ();
11821189
fn try_origin(o: O) -> Result<Self::Success, O> {
11831190
o.into().and_then(|o| match o {
1184-
RawOrigin::Members(n, m) if n * D >= N * m => Ok(()),
1191+
RawOrigin::Members(n, m) if n.saturating_mul(D) >= N.saturating_mul(m) => Ok(()),
11851192
r => Err(O::from(r)),
11861193
})
11871194
}

pallets/collective/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
1717

18-
#![allow(non_camel_case_types)]
18+
#![allow(non_camel_case_types, clippy::indexing_slicing, clippy::unwrap_used)]
1919

2020
use super::{Event as CollectiveEvent, *};
2121
use crate as pallet_collective;

pallets/commitments/src/benchmarking.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Benchmarking setup
22
#![cfg(feature = "runtime-benchmarks")]
3+
#![allow(clippy::arithmetic_side_effects)]
34
use super::*;
45

56
#[allow(unused)]
@@ -17,7 +18,11 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
1718
// This creates an `IdentityInfo` object with `num_fields` extra fields.
1819
// All data is pre-populated with some arbitrary bytes.
1920
fn create_identity_info<T: Config>(_num_fields: u32) -> CommitmentInfo<T::MaxFields> {
20-
let _data = Data::Raw(vec![0; 32].try_into().unwrap());
21+
let _data = Data::Raw(
22+
vec![0; 32]
23+
.try_into()
24+
.expect("vec length is less than 64; qed"),
25+
);
2126

2227
CommitmentInfo {
2328
fields: Default::default(),

pallets/commitments/src/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub use types::*;
1313
pub use weights::WeightInfo;
1414

1515
use frame_support::traits::Currency;
16-
use sp_runtime::traits::Zero;
16+
use sp_runtime::{traits::Zero, Saturating};
1717
use sp_std::boxed::Box;
1818

1919
type BalanceOf<T> =
@@ -137,12 +137,12 @@ pub mod pallet {
137137
let cur_block = <frame_system::Pallet<T>>::block_number();
138138
if let Some(last_commit) = <LastCommitment<T>>::get(netuid, &who) {
139139
ensure!(
140-
cur_block >= last_commit + T::RateLimit::get(),
140+
cur_block >= last_commit.saturating_add(T::RateLimit::get()),
141141
Error::<T>::CommitmentSetRateLimitExceeded
142142
);
143143
}
144144

145-
let fd = <BalanceOf<T>>::from(extra_fields) * T::FieldDeposit::get();
145+
let fd = <BalanceOf<T>>::from(extra_fields).saturating_mul(T::FieldDeposit::get());
146146
let mut id = match <CommitmentOf<T>>::get(netuid, &who) {
147147
Some(mut id) => {
148148
id.info = *info;
@@ -157,12 +157,13 @@ pub mod pallet {
157157
};
158158

159159
let old_deposit = id.deposit;
160-
id.deposit = T::InitialDeposit::get() + fd;
160+
id.deposit = T::InitialDeposit::get().saturating_add(fd);
161161
if id.deposit > old_deposit {
162-
T::Currency::reserve(&who, id.deposit - old_deposit)?;
162+
T::Currency::reserve(&who, id.deposit.saturating_sub(old_deposit))?;
163163
}
164164
if old_deposit > id.deposit {
165-
let err_amount = T::Currency::unreserve(&who, old_deposit - id.deposit);
165+
let err_amount =
166+
T::Currency::unreserve(&who, old_deposit.saturating_sub(id.deposit));
166167
debug_assert!(err_amount.is_zero());
167168
}
168169

pallets/commitments/src/types.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Decode for Data {
6767
Ok(match b {
6868
0 => Data::None,
6969
n @ 1..=129 => {
70-
let mut r: BoundedVec<_, _> = vec![0u8; n as usize - 1]
70+
let mut r: BoundedVec<_, _> = vec![0u8; (n as usize).saturating_sub(1)]
7171
.try_into()
7272
.expect("bound checked in match arm condition; qed");
7373
input.read(&mut r[..])?;
@@ -87,8 +87,8 @@ impl Encode for Data {
8787
match self {
8888
Data::None => vec![0u8; 1],
8989
Data::Raw(ref x) => {
90-
let l = x.len().min(128);
91-
let mut r = vec![l as u8 + 1];
90+
let l = x.len().min(128) as u8;
91+
let mut r = vec![l.saturating_add(1)];
9292
r.extend_from_slice(&x[..]);
9393
r
9494
}
@@ -346,6 +346,7 @@ impl<
346346
}
347347

348348
#[cfg(test)]
349+
#[allow(clippy::indexing_slicing, clippy::unwrap_used)]
349350
mod tests {
350351
use super::*;
351352

pallets/registry/src/benchmarking.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Benchmarking setup
22
#![cfg(feature = "runtime-benchmarks")]
3+
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]
34
use super::*;
45

56
#[allow(unused)]
@@ -19,7 +20,11 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
1920
// This creates an `IdentityInfo` object with `num_fields` extra fields.
2021
// All data is pre-populated with some arbitrary bytes.
2122
fn create_identity_info<T: Config>(_num_fields: u32) -> IdentityInfo<T::MaxAdditionalFields> {
22-
let data = Data::Raw(vec![0; 32].try_into().unwrap());
23+
let data = Data::Raw(
24+
vec![0; 32]
25+
.try_into()
26+
.expect("size does not exceed 64; qed"),
27+
);
2328

2429
IdentityInfo {
2530
additional: Default::default(),

pallets/registry/src/lib.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use frame_support::traits::tokens::{
1515
fungible::{self, MutateHold as _},
1616
Precision,
1717
};
18-
use sp_runtime::traits::Zero;
18+
use sp_runtime::{traits::Zero, Saturating};
1919
use sp_std::boxed::Box;
2020

2121
type BalanceOf<T> =
@@ -132,7 +132,7 @@ pub mod pallet {
132132
Error::<T>::TooManyFieldsInIdentityInfo
133133
);
134134

135-
let fd = <BalanceOf<T>>::from(extra_fields) * T::FieldDeposit::get();
135+
let fd = <BalanceOf<T>>::from(extra_fields).saturating_mul(T::FieldDeposit::get());
136136
let mut id = match <IdentityOf<T>>::get(&identified) {
137137
Some(mut id) => {
138138
id.info = *info;
@@ -145,23 +145,24 @@ pub mod pallet {
145145
};
146146

147147
let old_deposit = id.deposit;
148-
id.deposit = T::InitialDeposit::get() + fd;
148+
id.deposit = T::InitialDeposit::get().saturating_add(fd);
149149
if id.deposit > old_deposit {
150150
T::Currency::hold(
151151
&HoldReason::RegistryIdentity.into(),
152152
&who,
153-
id.deposit - old_deposit,
153+
id.deposit.saturating_sub(old_deposit),
154154
)?;
155155
}
156156
if old_deposit > id.deposit {
157157
let release_res = T::Currency::release(
158158
&HoldReason::RegistryIdentity.into(),
159159
&who,
160-
old_deposit - id.deposit,
160+
old_deposit.saturating_sub(id.deposit),
161161
Precision::BestEffort,
162162
);
163-
debug_assert!(release_res
164-
.is_ok_and(|released_amount| released_amount == (old_deposit - id.deposit)));
163+
debug_assert!(release_res.is_ok_and(
164+
|released_amount| released_amount == old_deposit.saturating_sub(id.deposit)
165+
));
165166
}
166167

167168
<IdentityOf<T>>::insert(&identified, id);

pallets/registry/src/types.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl Decode for Data {
6868
Ok(match b {
6969
0 => Data::None,
7070
n @ 1..=65 => {
71-
let mut r: BoundedVec<_, _> = vec![0u8; n as usize - 1]
71+
let mut r: BoundedVec<_, _> = vec![0u8; (n as usize).saturating_sub(1)]
7272
.try_into()
7373
.expect("bound checked in match arm condition; qed");
7474
input.read(&mut r[..])?;
@@ -88,8 +88,8 @@ impl Encode for Data {
8888
match self {
8989
Data::None => vec![0u8; 1],
9090
Data::Raw(ref x) => {
91-
let l = x.len().min(64);
92-
let mut r = vec![l as u8 + 1];
91+
let l = x.len().min(64) as u8;
92+
let mut r = vec![l.saturating_add(1)];
9393
r.extend_from_slice(&x[..]);
9494
r
9595
}
@@ -405,6 +405,7 @@ impl<
405405
}
406406

407407
#[cfg(test)]
408+
#[allow(clippy::indexing_slicing, clippy::unwrap_used)]
408409
mod tests {
409410
use super::*;
410411

pallets/subtensor/src/benchmarks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Subtensor pallet benchmarking.
2-
2+
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]
33
#![cfg(feature = "runtime-benchmarks")]
44

55
use crate::Pallet as Subtensor;

0 commit comments

Comments
 (0)