Skip to content

Use TryFrom impls instead of as operator in polkadot-runtime-parachains #8118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 48 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f94ac1a
explicit usize convertion
iulianbarbu Apr 1, 2025
73bd02a
fix compilation issues
iulianbarbu Apr 1, 2025
5d6c072
more compilation issues fixes
iulianbarbu Apr 1, 2025
a23c8b3
Update from github-actions[bot] running command 'prdoc'
github-actions[bot] Apr 1, 2025
09ef1b6
polished prdoc
iulianbarbu Apr 1, 2025
7a60b8a
fix title
iulianbarbu Apr 1, 2025
9161731
simplify fix
iulianbarbu Apr 1, 2025
8612c78
fix prdoc title
iulianbarbu Apr 1, 2025
10706cb
add audience
iulianbarbu Apr 1, 2025
e79f7b7
Merge branch 'master' into ib-fix-compilation-issues
iulianbarbu Apr 1, 2025
1d7980c
fix prdoc
iulianbarbu Apr 1, 2025
da3b68a
Bump deranged & time
bkchr Apr 4, 2025
611031b
fix compilation after upgrading degraded
iulianbarbu Apr 4, 2025
28aaff9
more fixes
iulianbarbu Apr 4, 2025
195349f
Update bridges/relays/messages/src/message_race_delivery.rs
bkchr Apr 5, 2025
1119588
fix compilation issue
iulianbarbu Apr 7, 2025
7d2a97d
fix more compilation issues
iulianbarbu Apr 7, 2025
c273bb8
one more fix
iulianbarbu Apr 7, 2025
eb99995
fix polkadot/service tests
iulianbarbu Apr 7, 2025
3dd4fb5
fix yet another
iulianbarbu Apr 7, 2025
a333b40
Update from github-actions[bot] running command 'prdoc --force'
github-actions[bot] Apr 7, 2025
70aa1de
Update prdoc/pr_8118.prdoc
iulianbarbu Apr 7, 2025
7a1b174
Update prdoc/pr_8118.prdoc
iulianbarbu Apr 7, 2025
a89df75
Update prdoc/pr_8118.prdoc
iulianbarbu Apr 7, 2025
8cf821e
Update prdoc/pr_8118.prdoc
iulianbarbu Apr 7, 2025
ca7416b
Apply suggestions from code review
iulianbarbu Apr 7, 2025
12f6db0
Update prdoc/pr_8118.prdoc
iulianbarbu Apr 7, 2025
89fd3bd
Update message_race_delivery.rs
iulianbarbu Apr 8, 2025
120906d
Update polkadot/node/core/chain-selection/src/db_backend/v1.rs
iulianbarbu Apr 8, 2025
adf6ac6
use explicit From conversions instead of 'as'
iulianbarbu Apr 8, 2025
b1e105a
remove unnecessary paranthesis
iulianbarbu Apr 8, 2025
3980374
handle out of bounds usize conversion
iulianbarbu Apr 9, 2025
4ab7d01
Update from github-actions[bot] running command 'fmt'
github-actions[bot] Apr 9, 2025
5a1274f
proper handling errors and rest of conversions
iulianbarbu Apr 9, 2025
a3a461d
Update from github-actions[bot] running command 'fmt'
github-actions[bot] Apr 9, 2025
00995ac
Merge branch 'master' into ib-fix-compilation-issues
iulianbarbu Apr 9, 2025
4257827
update prdoc and downgrade degrade to 0.4.0
iulianbarbu Apr 9, 2025
af5df68
fix prdoc
iulianbarbu Apr 9, 2025
e610b8f
Update prdoc/pr_8118.prdoc
iulianbarbu Apr 10, 2025
b26273a
rever unnecessary changes
iulianbarbu Apr 10, 2025
8d4d080
some leftovers
iulianbarbu Apr 10, 2025
2076e2c
Update from github-actions[bot] running command 'fmt'
github-actions[bot] Apr 10, 2025
ef51bd3
revert deranged upgrade
iulianbarbu Apr 11, 2025
14d5d9a
rever gitignore
iulianbarbu Apr 11, 2025
7ca6156
fix time hash in cargo.lock
iulianbarbu Apr 11, 2025
6dcdab2
Merge branch 'master' into ib-fix-compilation-issues
iulianbarbu Apr 11, 2025
aea2cae
Update polkadot/runtime/parachains/src/inclusion/mod.rs
bkchr Apr 11, 2025
44a5a0e
Update prdoc/pr_8118.prdoc
bkchr Apr 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ target/
*.scale
justfile
rustc-ice-*
.bacon-locations
bacon.log
bacon-ls.log
.config/bacon.toml
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bridges/modules/parachains/src/call_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<T: Config<I>, I: 'static> SubmitParachainHeadsHelper<T, I> {
.0
.checked_sub(stored_best_head.best_head_hash.at_relay_block_number)
{
Some(improved_by) if improved_by > Zero::zero() => improved_by,
Some(improved_by) if improved_by > u32::zero() => improved_by,
_ => {
log::trace!(
target: crate::LOG_TARGET,
Expand Down
2 changes: 1 addition & 1 deletion bridges/relays/messages/src/message_race_delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ where
.flat_map(|(_, subrange)| {
subrange
.iter()
.filter(|(nonce, _)| range.contains(nonce))
.filter(|(nonce, _)| range.contains(*nonce))
.map(|(_, details)| details.dispatch_weight)
})
.fold(Weight::zero(), |total, weight| total.saturating_add(weight))
Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/parachain-system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl BlockTests {
.unwrap_or(*n as RelayChainBlockNumber);
// clear pending updates, as applicable
if let Some(upgrade_block) = self.pending_upgrade {
if n >= &upgrade_block.into() {
if n >= &(upgrade_block as u64) {
self.pending_upgrade = None;
}
}
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/core/approval-voting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ impl ChainBuilder {
parent_hash != Self::GENESIS_PARENT_HASH,
"cannot add block with genesis parent hash"
);
assert!(self.blocks_by_hash.len() < u8::MAX.into());
assert!(self.blocks_by_hash.len() < u8::MAX as usize);
self.add_block_inner(hash, parent_hash, number, config)
}

Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/core/chain-selection/src/db_backend/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl Backend for DbBackend {
})
.enumerate()
.take_while(|(idx, r)| {
r.as_ref().map_or(true, |(at, _)| *at <= up_to.into() && *idx < max_elements)
r.as_ref().map_or(true, |(at, _)| *at <= up_to as u64 && *idx < max_elements)
})
.map(|(_, v)| v)
.collect::<Result<Vec<_>, _>>()?;
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/service/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl ChainBuilder {
parent_hash != Self::GENESIS_PARENT_HASH,
"cannot add block with genesis parent hash"
);
assert!(self.0.blocks_by_hash.len() < u8::MAX.into());
assert!(self.0.blocks_by_hash.len() < u8::MAX as usize);
self.add_block_inner(hash, parent_hash, number)
}

Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/common/src/crowdloan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ pub mod pallet {
pub fn add_memo(origin: OriginFor<T>, index: ParaId, memo: Vec<u8>) -> DispatchResult {
let who = ensure_signed(origin)?;

ensure!(memo.len() <= T::MaxMemoLength::get().into(), Error::<T>::MemoTooLarge);
ensure!(memo.len() <= T::MaxMemoLength::get() as usize, Error::<T>::MemoTooLarge);
let fund = Funds::<T>::get(index).ok_or(Error::<T>::InvalidParaId)?;

let (balance, _) = Self::contribution_get(fund.fund_index, &who);
Expand Down
4 changes: 2 additions & 2 deletions polkadot/runtime/parachains/src/inclusion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ impl<T: Config> CandidateCheckContext<T> {
horizontal_messages: &[polkadot_primitives::OutboundHrmpMessage<ParaId>],
) -> Result<(), AcceptanceCheckErr> {
ensure!(
head_data.0.len() <= self.config.max_head_data_size as _,
head_data.0.len() <= self.config.max_head_data_size as usize,
AcceptanceCheckErr::HeadDataTooLarge,
);

Expand All @@ -1331,7 +1331,7 @@ impl<T: Config> CandidateCheckContext<T> {
AcceptanceCheckErr::PrematureCodeUpgrade,
);
ensure!(
new_validation_code.0.len() <= self.config.max_code_size as _,
new_validation_code.0.len() <= self.config.max_code_size as usize,
AcceptanceCheckErr::NewCodeTooLarge,
);
}
Expand Down
34 changes: 34 additions & 0 deletions prdoc/pr_8118.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
title: Fix compilation by making conversions explicit
doc:
- audience: [Node Dev, Runtime Dev]
description: |-
Fix various compilation issues for crates in polkadot-sdk after upgrading degrade to 0.4.1.
crates:
- name: polkadot-runtime-parachains
bump: patch
- name: pallet-bridge-parachains
bump: patch
- name: polkadot-node-core-chain-selection
bump: patch
- name: polkadot-runtime-common
bump: patch
- name: substrate-wasm-builder
bump: patch
- name: pallet-revive
bump: patch
- name: pallet-society
bump: patch
- name: pallet-staking
bump: patch
- name: sp-npos-elections
bump: patch
- name: pallet-broker
bump: patch
- name: pallet-nomination-pools
bump: patch
- name: polkadot-node-core-approval-voting
bump: patch
- name: polkadot-service
bump: patch
- name: cumulus-pallet-parachain-system
bump: patch
2 changes: 1 addition & 1 deletion substrate/frame/broker/src/core_mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ mod tests {
assert_eq!(u128::from(CoreMask::complete()), 0xfffff_fffff_fffff_fffff);
assert_eq!(
0x12345_67890_abcde_f0123u128,
CoreMask([0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x01, 0x23]).into(),
u128::from(CoreMask([0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x01, 0x23])),
);
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/nomination-pools/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ mod test {
use super::*;
#[test]
fn u256_to_balance_convert_works() {
assert_eq!(U256ToBalance::convert(0u32.into()), Zero::zero());
assert_eq!(U256ToBalance::convert(0u32.into()), u128::zero());
assert_eq!(U256ToBalance::convert(Balance::max_value().into()), Balance::max_value())
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub mod code {
(program.code().len() as u64).saturating_mul(EXTRA_OVERHEAD_PER_CODE_BYTE.into()),
);

if memory_size > STATIC_MEMORY_BYTES.into() {
if memory_size > STATIC_MEMORY_BYTES as u64 {
log::debug!(target: LOG_TARGET, "static memory too large: {memory_size} limit: {STATIC_MEMORY_BYTES}");
return Err(Error::<T>::StaticMemoryTooLarge.into())
}
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/society/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ fn bidding_works() {
assert_eq!(Pot::<Test>::get(), 1_800);
assert_eq!(Balances::free_balance(Society::account_id()), 8_800);
// No more candidates satisfy the requirements
assert_eq!(candidacies(), vec![]);
assert_eq!(candidacies(), vec![] as Vec<(u128, Candidacy<u128, u64>)>);
assert_ok!(Society::defender_vote(Origin::signed(10), true)); // Keep defender around
// Next period
System::run_to_block::<AllPalletsWithSystem>(16);
Expand Down Expand Up @@ -587,7 +587,7 @@ fn suspended_candidate_rejected_works() {
next_intake();
conclude_intake(false, None);
assert_eq!(members(), vec![10, 20, 30, 40, 50]);
assert_eq!(candidates(), vec![]);
assert_eq!(candidates(), vec![] as Vec<u128>);
assert_eq!(Balances::free_balance(60), 25);
assert_eq!(Balances::reserved_balance(60), 0);
assert_eq!(Balances::free_balance(Society::account_id()), 10030);
Expand Down Expand Up @@ -1301,7 +1301,7 @@ fn resign_candidacy_works() {
assert_eq!(candidates(), vec![30]);
assert_ok!(Society::resign_candidacy(Origin::signed(30)));
// 30 candidacy has gone.
assert_eq!(candidates(), vec![]);
assert_eq!(candidates(), vec![] as Vec<u128>);
});
}

Expand All @@ -1318,6 +1318,6 @@ fn drop_candidate_works() {
System::run_to_block::<AllPalletsWithSystem>(12);
assert_ok!(Society::drop_candidate(Origin::signed(50), 40));
// 40 candidacy has gone.
assert_eq!(candidates(), vec![]);
assert_eq!(candidates(), vec![] as Vec<u128>);
});
}
4 changes: 2 additions & 2 deletions substrate/frame/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7363,8 +7363,8 @@ mod ledger {
assert_eq!(ledger_updated.stash, stash);

// Check `active` and `total` values match the original ledger set by controller.
assert_eq!(ledger_updated.active, (10 + ctlr).into());
assert_eq!(ledger_updated.total, (10 + ctlr).into());
assert_eq!(ledger_updated.active, (10 + ctlr) as u128);
assert_eq!(ledger_updated.total, (10 + ctlr) as u128);
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/npos-elections/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ pub fn check_assignments_sum<T: PerThing>(assignments: &[Assignment<AccountId, T
distribution
.iter()
.for_each(|(_, p)| sum += p.deconstruct().saturated_into::<u128>());
assert_eq!(sum, T::ACCURACY.saturated_into(), "Assignment ratio sum is not 100%");
assert_eq!(sum, T::ACCURACY.saturated_into::<u128>(), "Assignment ratio sum is not 100%");
}
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/utils/wasm-builder/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Ord for Version {

to_compare
.iter()
.find_map(|(l, r)| if l != r { l.partial_cmp(&r) } else { None })
.find_map(|(l, r)| if l != r { l.partial_cmp(r) } else { None })
// We already checked this right at the beginning, so we should never return here
// `Equal`.
.unwrap_or(Ordering::Equal)
Expand Down
Loading