From fa123dceb59ae37a56479ed77b08694a4b94334e Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 17 May 2022 23:53:14 +0200 Subject: [PATCH] Co #10719: Use `into_account_truncating` (#4947) * Use into_account_truncating Signed-off-by: Oliver Tale-Yazdi * more truncating * more truncating * more * clean up parachain primitives * more truncating * update lockfile for {"substrate"} Co-authored-by: Shawn Tabrizi Co-authored-by: parity-processbot <> --- .../runtime/common/src/crowdloan/migration.rs | 2 +- polkadot/runtime/common/src/crowdloan/mod.rs | 2 +- .../runtime/common/src/slots/migration.rs | 2 +- polkadot/runtime/parachains/src/hrmp.rs | 14 +++--- .../parachains/src/hrmp/benchmarking.rs | 4 +- polkadot/runtime/parachains/src/hrmp/tests.rs | 46 +++++++++++++------ 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/polkadot/runtime/common/src/crowdloan/migration.rs b/polkadot/runtime/common/src/crowdloan/migration.rs index 5951125981..dec19a1ff5 100644 --- a/polkadot/runtime/common/src/crowdloan/migration.rs +++ b/polkadot/runtime/common/src/crowdloan/migration.rs @@ -23,7 +23,7 @@ pub mod crowdloan_index_migration { // The old way we generated fund accounts. fn old_fund_account_id(index: ParaId) -> T::AccountId { - T::PalletId::get().into_sub_account(index) + T::PalletId::get().into_sub_account_truncating(index) } pub fn pre_migrate() -> Result<(), &'static str> { diff --git a/polkadot/runtime/common/src/crowdloan/mod.rs b/polkadot/runtime/common/src/crowdloan/mod.rs index bbb74c634a..fa886f0144 100644 --- a/polkadot/runtime/common/src/crowdloan/mod.rs +++ b/polkadot/runtime/common/src/crowdloan/mod.rs @@ -661,7 +661,7 @@ impl Pallet { /// This actually does computation. If you need to keep using it, then make sure you cache the /// value and only call this once. pub fn fund_account_id(index: FundIndex) -> T::AccountId { - T::PalletId::get().into_sub_account(index) + T::PalletId::get().into_sub_account_truncating(index) } pub fn id_from_index(index: FundIndex) -> child::ChildInfo { diff --git a/polkadot/runtime/common/src/slots/migration.rs b/polkadot/runtime/common/src/slots/migration.rs index b59ab35d4c..b995ace230 100644 --- a/polkadot/runtime/common/src/slots/migration.rs +++ b/polkadot/runtime/common/src/slots/migration.rs @@ -24,7 +24,7 @@ pub mod slots_crowdloan_index_migration { // The old way we generated fund accounts. fn old_fund_account_id(index: ParaId) -> T::AccountId { - ::PalletId::get().into_sub_account(index) + ::PalletId::get().into_sub_account_truncating(index) } pub fn pre_migrate() -> Result<(), &'static str> { diff --git a/polkadot/runtime/parachains/src/hrmp.rs b/polkadot/runtime/parachains/src/hrmp.rs index 0f221dfa4b..d18c2b3fc4 100644 --- a/polkadot/runtime/parachains/src/hrmp.rs +++ b/polkadot/runtime/parachains/src/hrmp.rs @@ -687,7 +687,7 @@ impl Pallet { // Return the deposit of the sender, but only if it is not the para being offboarded. if !outgoing.contains(&req_id.sender) { T::Currency::unreserve( - &req_id.sender.into_account(), + &req_id.sender.into_account_truncating(), req_data.sender_deposit.unique_saturated_into(), ); } @@ -700,7 +700,7 @@ impl Pallet { if req_data.confirmed { if !outgoing.contains(&req_id.recipient) { T::Currency::unreserve( - &req_id.recipient.into_account(), + &req_id.recipient.into_account_truncating(), config.hrmp_recipient_deposit.unique_saturated_into(), ); } @@ -817,11 +817,11 @@ impl Pallet { ::HrmpChannels::take(channel_id) { T::Currency::unreserve( - &channel_id.sender.into_account(), + &channel_id.sender.into_account_truncating(), sender_deposit.unique_saturated_into(), ); T::Currency::unreserve( - &channel_id.recipient.into_account(), + &channel_id.recipient.into_account_truncating(), recipient_deposit.unique_saturated_into(), ); } @@ -1137,7 +1137,7 @@ impl Pallet { ); T::Currency::reserve( - &origin.into_account(), + &origin.into_account_truncating(), config.hrmp_sender_deposit.unique_saturated_into(), )?; @@ -1210,7 +1210,7 @@ impl Pallet { ); T::Currency::reserve( - &origin.into_account(), + &origin.into_account_truncating(), config.hrmp_recipient_deposit.unique_saturated_into(), )?; @@ -1264,7 +1264,7 @@ impl Pallet { // Unreserve the sender's deposit. The recipient could not have left their deposit because // we ensured that the request is not confirmed. T::Currency::unreserve( - &channel_id.sender.into_account(), + &channel_id.sender.into_account_truncating(), open_channel_req.sender_deposit.unique_saturated_into(), ); diff --git a/polkadot/runtime/parachains/src/hrmp/benchmarking.rs b/polkadot/runtime/parachains/src/hrmp/benchmarking.rs index ddce64601f..3486e990fe 100644 --- a/polkadot/runtime/parachains/src/hrmp/benchmarking.rs +++ b/polkadot/runtime/parachains/src/hrmp/benchmarking.rs @@ -36,7 +36,7 @@ fn register_parachain_with_balance(id: ParaId, balance: BalanceOf) validation_code: vec![1].into(), }, ); - T::Currency::make_free_balance_be(&id.into_account(), balance); + T::Currency::make_free_balance_be(&id.into_account_truncating(), balance); } fn assert_last_event(generic_event: ::Event) { @@ -201,7 +201,7 @@ frame_benchmarking::benchmarks! { let para: ParaId = 1u32.into(); let para_origin: crate::Origin = 1u32.into(); register_parachain_with_balance::(para, deposit); - T::Currency::make_free_balance_be(¶.into_account(), deposit * 256u32.into()); + T::Currency::make_free_balance_be(¶.into_account_truncating(), deposit * 256u32.into()); for ingress_para_id in 0..i { // establish ingress channels to `para`. diff --git a/polkadot/runtime/parachains/src/hrmp/tests.rs b/polkadot/runtime/parachains/src/hrmp/tests.rs index ad7871e1f9..463c5eb393 100644 --- a/polkadot/runtime/parachains/src/hrmp/tests.rs +++ b/polkadot/runtime/parachains/src/hrmp/tests.rs @@ -135,7 +135,7 @@ fn register_parachain_with_balance(id: ParaId, balance: Balance) { validation_code: vec![1].into(), }, )); - ::Currency::make_free_balance_be(&id.into_account(), balance); + ::Currency::make_free_balance_be(&id.into_account_truncating(), balance); } fn register_parachain(id: ParaId) { @@ -490,15 +490,21 @@ fn refund_deposit_on_normal_closure() { run_to_block(5, Some(vec![4, 5])); Hrmp::init_open_channel(para_a, para_b, 2, 8).unwrap(); Hrmp::accept_open_channel(para_b, para_a).unwrap(); - assert_eq!(::Currency::free_balance(¶_a.into_account()), 80); - assert_eq!(::Currency::free_balance(¶_b.into_account()), 95); + assert_eq!(::Currency::free_balance(¶_a.into_account_truncating()), 80); + assert_eq!(::Currency::free_balance(¶_b.into_account_truncating()), 95); run_to_block(8, Some(vec![8])); // Now, we close the channel and wait until the next session. Hrmp::close_channel(para_b, HrmpChannelId { sender: para_a, recipient: para_b }).unwrap(); run_to_block(10, Some(vec![10])); - assert_eq!(::Currency::free_balance(¶_a.into_account()), 100); - assert_eq!(::Currency::free_balance(¶_b.into_account()), 110); + assert_eq!( + ::Currency::free_balance(¶_a.into_account_truncating()), + 100 + ); + assert_eq!( + ::Currency::free_balance(¶_b.into_account_truncating()), + 110 + ); }); } @@ -517,8 +523,8 @@ fn refund_deposit_on_offboarding() { run_to_block(5, Some(vec![4, 5])); Hrmp::init_open_channel(para_a, para_b, 2, 8).unwrap(); Hrmp::accept_open_channel(para_b, para_a).unwrap(); - assert_eq!(::Currency::free_balance(¶_a.into_account()), 80); - assert_eq!(::Currency::free_balance(¶_b.into_account()), 95); + assert_eq!(::Currency::free_balance(¶_a.into_account_truncating()), 80); + assert_eq!(::Currency::free_balance(¶_b.into_account_truncating()), 95); run_to_block(8, Some(vec![8])); assert!(channel_exists(para_a, para_b)); @@ -531,8 +537,14 @@ fn refund_deposit_on_offboarding() { assert!(!channel_exists(para_a, para_b)); Hrmp::assert_storage_consistency_exhaustive(); - assert_eq!(::Currency::free_balance(¶_a.into_account()), 100); - assert_eq!(::Currency::free_balance(¶_b.into_account()), 110); + assert_eq!( + ::Currency::free_balance(¶_a.into_account_truncating()), + 100 + ); + assert_eq!( + ::Currency::free_balance(¶_b.into_account_truncating()), + 110 + ); }); } @@ -552,7 +564,7 @@ fn no_dangling_open_requests() { // Start opening a channel a->b Hrmp::init_open_channel(para_a, para_b, 2, 8).unwrap(); - assert_eq!(::Currency::free_balance(¶_a.into_account()), 80); + assert_eq!(::Currency::free_balance(¶_a.into_account_truncating()), 80); // Then deregister one parachain, but don't wait two sessions until it takes effect. // Instead, `para_b` will confirm the request, which will take place the same time @@ -560,12 +572,15 @@ fn no_dangling_open_requests() { deregister_parachain(para_a); run_to_block(9, Some(vec![9])); Hrmp::accept_open_channel(para_b, para_a).unwrap(); - assert_eq!(::Currency::free_balance(¶_b.into_account()), 95); + assert_eq!(::Currency::free_balance(¶_b.into_account_truncating()), 95); assert!(!channel_exists(para_a, para_b)); run_to_block(10, Some(vec![10])); // The outcome we expect is `para_b` should receive the refund. - assert_eq!(::Currency::free_balance(¶_b.into_account()), 110); + assert_eq!( + ::Currency::free_balance(¶_b.into_account_truncating()), + 110 + ); assert!(!channel_exists(para_a, para_b)); Hrmp::assert_storage_consistency_exhaustive(); }); @@ -587,12 +602,15 @@ fn cancel_pending_open_channel_request() { // Start opening a channel a->b Hrmp::init_open_channel(para_a, para_b, 2, 8).unwrap(); - assert_eq!(::Currency::free_balance(¶_a.into_account()), 80); + assert_eq!(::Currency::free_balance(¶_a.into_account_truncating()), 80); // Cancel opening the channel Hrmp::cancel_open_request(para_a, HrmpChannelId { sender: para_a, recipient: para_b }) .unwrap(); - assert_eq!(::Currency::free_balance(¶_a.into_account()), 100); + assert_eq!( + ::Currency::free_balance(¶_a.into_account_truncating()), + 100 + ); run_to_block(10, Some(vec![10])); assert!(!channel_exists(para_a, para_b));