From 9545c94070c9d3320cdd2c883456ff1c2bbf0779 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Thu, 22 Jul 2021 14:04:23 +0200 Subject: [PATCH 1/9] WIP --- bin/node/runtime/src/lib.rs | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 82e3a9f7e084e..f18836f2d6077 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1176,6 +1176,51 @@ impl pallet_transaction_storage::Config for Runtime { type WeightInfo = pallet_transaction_storage::weights::SubstrateWeight; } +#[test] +fn foo() { + println!("System{}", std::mem::size_of::>()); + println!("Utility{}", std::mem::size_of::>()); + println!("Babe{}", std::mem::size_of::>()); + println!("Timestamp{}", std::mem::size_of::>()); + println!("Authorship{}", std::mem::size_of::>()); + println!("Indices{}", std::mem::size_of::>()); + println!("Balances{}", std::mem::size_of::>()); + println!("TransactionPayment{}", std::mem::size_of::>()); + println!("ElectionProviderMultiPhase{}", std::mem::size_of::>()); + println!("Staking{}", std::mem::size_of::>()); + println!("Session{}", std::mem::size_of::>()); + println!("Democracy{}", std::mem::size_of::>()); + println!("Council{}", std::mem::size_of::>()); + println!("TechnicalCommittee{}", std::mem::size_of::>()); + println!("Elections{}", std::mem::size_of::>()); + println!("TechnicalMembership{}", std::mem::size_of::>()); + println!("Grandpa{}", std::mem::size_of::>()); + println!("Treasury{}", std::mem::size_of::>()); + println!("Contracts{}", std::mem::size_of::>()); + println!("Sudo{}", std::mem::size_of::>()); + println!("ImOnline{}", std::mem::size_of::>()); + println!("AuthorityDiscovery{}", std::mem::size_of::>()); + println!("Offences{}", std::mem::size_of::>()); + println!("Historical{}", std::mem::size_of::>()); + println!("RandomnessCollectiveFlip{}", std::mem::size_of::>()); + println!("Identity{}", std::mem::size_of::>()); + println!("Society{}", std::mem::size_of::>()); + println!("Recovery{}", std::mem::size_of::>()); + println!("Vesting{}", std::mem::size_of::>()); + println!("Scheduler{}", std::mem::size_of::>()); + println!("Proxy{}", std::mem::size_of::>()); + println!("Multisig{}", std::mem::size_of::>()); + println!("Bounties{}", std::mem::size_of::>()); + println!("Tips{}", std::mem::size_of::>()); + println!("Assets{}", std::mem::size_of::>()); + println!("Mmr{}", std::mem::size_of::>()); + println!("Lottery{}", std::mem::size_of::>()); + println!("Gilt{}", std::mem::size_of::>()); + println!("Uniques{}", std::mem::size_of::>()); + println!("TransactionStorage{}", std::mem::size_of::>()); + panic!(); +} + construct_runtime!( pub enum Runtime where Block = Block, From a960b9e7ce1852a9c0c9733bad88739303cd8416 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Thu, 22 Jul 2021 15:33:02 +0200 Subject: [PATCH 2/9] WIP --- frame/babe/src/equivocation.rs | 5 +- frame/babe/src/lib.rs | 8 +-- frame/babe/src/tests.rs | 51 +++++++++++++------ .../src/benchmarking.rs | 14 +++-- .../election-provider-multi-phase/src/lib.rs | 10 ++-- .../src/signed.rs | 8 ++- .../src/unsigned.rs | 26 ++++++---- 7 files changed, 80 insertions(+), 42 deletions(-) diff --git a/frame/babe/src/equivocation.rs b/frame/babe/src/equivocation.rs index 95abd87787b4a..2d0cc6c2c26a7 100644 --- a/frame/babe/src/equivocation.rs +++ b/frame/babe/src/equivocation.rs @@ -155,7 +155,10 @@ where ) -> DispatchResult { use frame_system::offchain::SubmitTransaction; - let call = Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof); + let call = Call::report_equivocation_unsigned( + Box::new(equivocation_proof), + key_owner_proof, + ); match SubmitTransaction::>::submit_unsigned_transaction(call.into()) { Ok(()) => log::info!( diff --git a/frame/babe/src/lib.rs b/frame/babe/src/lib.rs index 949f55720bbd2..5ba96da7fbd3a 100644 --- a/frame/babe/src/lib.rs +++ b/frame/babe/src/lib.rs @@ -342,12 +342,12 @@ pub mod pallet { ))] pub fn report_equivocation( origin: OriginFor, - equivocation_proof: EquivocationProof, + equivocation_proof: Box>, key_owner_proof: T::KeyOwnerProof, ) -> DispatchResultWithPostInfo { let reporter = ensure_signed(origin)?; - Self::do_report_equivocation(Some(reporter), equivocation_proof, key_owner_proof) + Self::do_report_equivocation(Some(reporter), *equivocation_proof, key_owner_proof) } /// Report authority equivocation/misbehavior. This method will verify @@ -363,14 +363,14 @@ pub mod pallet { ))] pub fn report_equivocation_unsigned( origin: OriginFor, - equivocation_proof: EquivocationProof, + equivocation_proof: Box>, key_owner_proof: T::KeyOwnerProof, ) -> DispatchResultWithPostInfo { ensure_none(origin)?; Self::do_report_equivocation( T::HandleEquivocation::block_author(), - equivocation_proof, + *equivocation_proof, key_owner_proof, ) } diff --git a/frame/babe/src/tests.rs b/frame/babe/src/tests.rs index 5e72e14877a48..8b3a00ee33ce5 100644 --- a/frame/babe/src/tests.rs +++ b/frame/babe/src/tests.rs @@ -415,7 +415,11 @@ fn report_equivocation_current_session_works() { let key_owner_proof = Historical::prove(key).unwrap(); // report the equivocation - Babe::report_equivocation_unsigned(Origin::none(), equivocation_proof, key_owner_proof) + Babe::report_equivocation_unsigned( + Origin::none(), + Box::new(equivocation_proof), + key_owner_proof, + ) .unwrap(); // start a new era so that the results of the offence report @@ -483,7 +487,11 @@ fn report_equivocation_old_session_works() { assert_eq!(Staking::slashable_balance_of(&offending_validator_id), 10_000); // report the equivocation - Babe::report_equivocation_unsigned(Origin::none(), equivocation_proof, key_owner_proof) + Babe::report_equivocation_unsigned( + Origin::none(), + Box::new(equivocation_proof), + key_owner_proof, + ) .unwrap(); // start a new era so that the results of the offence report @@ -533,7 +541,7 @@ fn report_equivocation_invalid_key_owner_proof() { assert_err!( Babe::report_equivocation_unsigned( Origin::none(), - equivocation_proof.clone(), + Box::new(equivocation_proof.clone()), key_owner_proof ), Error::::InvalidKeyOwnershipProof, @@ -551,7 +559,11 @@ fn report_equivocation_invalid_key_owner_proof() { start_era(2); assert_err!( - Babe::report_equivocation_unsigned(Origin::none(), equivocation_proof, key_owner_proof), + Babe::report_equivocation_unsigned( + Origin::none(), + Box::new(equivocation_proof), + key_owner_proof, + ), Error::::InvalidKeyOwnershipProof, ); }) @@ -583,7 +595,7 @@ fn report_equivocation_invalid_equivocation_proof() { assert_err!( Babe::report_equivocation_unsigned( Origin::none(), - equivocation_proof, + Box::new(equivocation_proof), key_owner_proof.clone(), ), Error::::InvalidEquivocationProof, @@ -689,8 +701,10 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() { let key = (sp_consensus_babe::KEY_TYPE, &offending_authority_pair.public()); let key_owner_proof = Historical::prove(key).unwrap(); - let inner = - Call::report_equivocation_unsigned(equivocation_proof.clone(), key_owner_proof.clone()); + let inner = Call::report_equivocation_unsigned( + Box::new(equivocation_proof.clone()), + key_owner_proof.clone(), + ); // only local/inblock reports are allowed assert_eq!( @@ -721,7 +735,11 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() { assert_ok!(::pre_dispatch(&inner)); // we submit the report - Babe::report_equivocation_unsigned(Origin::none(), equivocation_proof, key_owner_proof) + Babe::report_equivocation_unsigned( + Origin::none(), + Box::new(equivocation_proof), + key_owner_proof + ) .unwrap(); // the report should now be considered stale and the transaction is invalid. @@ -780,7 +798,7 @@ fn valid_equivocation_reports_dont_pay_fees() { // check the dispatch info for the call. let info = Call::::report_equivocation_unsigned( - equivocation_proof.clone(), + Box::new(equivocation_proof.clone()), key_owner_proof.clone(), ) .get_dispatch_info(); @@ -792,7 +810,7 @@ fn valid_equivocation_reports_dont_pay_fees() { // report the equivocation. let post_info = Babe::report_equivocation_unsigned( Origin::none(), - equivocation_proof.clone(), + Box::new(equivocation_proof.clone()), key_owner_proof.clone(), ) .unwrap(); @@ -804,11 +822,14 @@ fn valid_equivocation_reports_dont_pay_fees() { // report the equivocation again which is invalid now since it is // duplicate. - let post_info = - Babe::report_equivocation_unsigned(Origin::none(), equivocation_proof, key_owner_proof) - .err() - .unwrap() - .post_info; + let post_info = Babe::report_equivocation_unsigned( + Origin::none(), + Box::new(equivocation_proof), + key_owner_proof, + ) + .err() + .unwrap() + .post_info; // the fee is not waived and the original weight is kept. assert!(post_info.actual_weight.is_none()); diff --git a/frame/election-provider-multi-phase/src/benchmarking.rs b/frame/election-provider-multi-phase/src/benchmarking.rs index 5e89db7537d07..5c8a42baf4d52 100644 --- a/frame/election-provider-multi-phase/src/benchmarking.rs +++ b/frame/election-provider-multi-phase/src/benchmarking.rs @@ -26,7 +26,7 @@ use rand::{prelude::SliceRandom, rngs::SmallRng, SeedableRng}; use sp_arithmetic::{per_things::Percent, traits::One}; use sp_npos_elections::IndexAssignment; use sp_runtime::InnerOf; -use sp_std::convert::{TryFrom, TryInto}; +use sp_std::{convert::{TryFrom, TryInto}, boxed::Box}; const SEED: u32 = 999; @@ -317,7 +317,7 @@ frame_benchmarking::benchmarks! { let caller = frame_benchmarking::whitelisted_caller(); T::Currency::make_free_balance_be(&caller, T::Currency::minimum_balance() * 10u32.into()); - }: _(RawOrigin::Signed(caller), solution, c) + }: _(RawOrigin::Signed(caller), Box::new(solution), c) verify { assert!(>::signed_submissions().len() as u32 == c + 1); } @@ -344,9 +344,15 @@ frame_benchmarking::benchmarks! { // encode the most significant storage item that needs to be decoded in the dispatch. let encoded_snapshot = >::snapshot().unwrap().encode(); - let encoded_call = >::submit_unsigned(raw_solution.clone(), witness).encode(); + let encoded_call = >::submit_unsigned(Box::new(raw_solution.clone()), witness).encode(); }: { - assert_ok!(>::submit_unsigned(RawOrigin::None.into(), raw_solution, witness)); + assert_ok!( + >::submit_unsigned( + RawOrigin::None.into(), + Box::new(raw_solution), + witness, + ) + ); let _decoded_snap = as Decode>::decode(&mut &*encoded_snapshot) .unwrap(); let _decoded_call = as Decode>::decode(&mut &*encoded_call).unwrap(); diff --git a/frame/election-provider-multi-phase/src/lib.rs b/frame/election-provider-multi-phase/src/lib.rs index 905492d6ca04c..884a1a02d1764 100644 --- a/frame/election-provider-multi-phase/src/lib.rs +++ b/frame/election-provider-multi-phase/src/lib.rs @@ -854,7 +854,7 @@ pub mod pallet { ))] pub fn submit_unsigned( origin: OriginFor, - solution: RawSolution>, + solution: Box>>, witness: SolutionOrSnapshotSize, ) -> DispatchResultWithPostInfo { ensure_none(origin)?; @@ -873,7 +873,7 @@ pub mod pallet { assert!(targets as u32 == witness.targets, "{}", error_message); let ready = - Self::feasibility_check(solution, ElectionCompute::Unsigned).expect(error_message); + Self::feasibility_check(*solution, ElectionCompute::Unsigned).expect(error_message); // Store the newly received solution. log!(info, "queued unsigned solution with score {:?}", ready.score); @@ -944,7 +944,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::submit(*num_signed_submissions))] pub fn submit( origin: OriginFor, - solution: RawSolution>, + solution: Box>>, num_signed_submissions: u32, ) -> DispatchResult { let who = ensure_signed(origin)?; @@ -973,7 +973,7 @@ pub mod pallet { // create the submission let deposit = Self::deposit_for(&solution, size); - let submission = SignedSubmission { who: who.clone(), deposit, solution }; + let submission = SignedSubmission { who: who.clone(), deposit, solution: *solution }; // insert the submission if the queue has space or it's better than the weakest // eject the weakest if the queue was full @@ -1918,7 +1918,7 @@ mod tests { let solution = RawSolution { score: [(5 + s).into(), 0, 0], ..Default::default() }; assert_ok!(MultiPhase::submit( crate::mock::Origin::signed(99), - solution, + Box::new(solution), MultiPhase::signed_submissions().len() as u32 )); } diff --git a/frame/election-provider-multi-phase/src/signed.rs b/frame/election-provider-multi-phase/src/signed.rs index c91c923d93e90..2a198043e7d31 100644 --- a/frame/election-provider-multi-phase/src/signed.rs +++ b/frame/election-provider-multi-phase/src/signed.rs @@ -499,7 +499,11 @@ mod tests { origin: Origin, solution: RawSolution>, ) -> DispatchResult { - MultiPhase::submit(origin, solution, MultiPhase::signed_submissions().len() as u32) + MultiPhase::submit( + origin, + Box::new(solution), + MultiPhase::signed_submissions().len() as u32, + ) } #[test] @@ -532,7 +536,7 @@ mod tests { // now try and cheat by passing a lower queue length assert_noop!( - MultiPhase::submit(Origin::signed(99), solution, 0), + MultiPhase::submit(Origin::signed(99), Box::new(solution), 0), Error::::SignedInvalidWitness, ); }) diff --git a/frame/election-provider-multi-phase/src/unsigned.rs b/frame/election-provider-multi-phase/src/unsigned.rs index 93e3878a71526..0c46ea8eaa646 100644 --- a/frame/election-provider-multi-phase/src/unsigned.rs +++ b/frame/election-provider-multi-phase/src/unsigned.rs @@ -34,7 +34,7 @@ use sp_runtime::{ traits::TrailingZeroInput, DispatchError, SaturatedConversion, }; -use sp_std::{cmp::Ordering, convert::TryFrom, vec::Vec}; +use sp_std::{cmp::Ordering, convert::TryFrom, vec::Vec, boxed::Box}; /// Storage key used to store the last block number at which offchain worker ran. pub(crate) const OFFCHAIN_LAST_BLOCK: &[u8] = b"parity/multi-phase-unsigned-election"; @@ -208,7 +208,7 @@ impl Pallet { let (raw_solution, witness) = Self::mine_and_check(iters)?; let score = raw_solution.score.clone(); - let call: Call = Call::submit_unsigned(raw_solution, witness).into(); + let call: Call = Call::submit_unsigned(Box::new(raw_solution), witness).into(); log!( debug, @@ -773,7 +773,7 @@ mod tests { fn validate_unsigned_retracts_wrong_phase() { ExtBuilder::default().desired_targets(0).build_and_execute(|| { let solution = RawSolution:: { score: [5, 0, 0], ..Default::default() }; - let call = Call::submit_unsigned(solution.clone(), witness()); + let call = Call::submit_unsigned(Box::new(solution.clone()), witness()); // initial assert_eq!(MultiPhase::current_phase(), Phase::Off); @@ -842,7 +842,7 @@ mod tests { assert!(MultiPhase::current_phase().is_unsigned()); let solution = RawSolution:: { score: [5, 0, 0], ..Default::default() }; - let call = Call::submit_unsigned(solution.clone(), witness()); + let call = Call::submit_unsigned(Box::new(solution.clone()), witness()); // initial assert!(::validate_unsigned( @@ -879,7 +879,7 @@ mod tests { assert!(MultiPhase::current_phase().is_unsigned()); let solution = RawSolution:: { score: [5, 0, 0], ..Default::default() }; - let call = Call::submit_unsigned(solution.clone(), witness()); + let call = Call::submit_unsigned(Box::new(solution.clone()), witness()); assert_eq!(solution.compact.unique_targets().len(), 0); // won't work anymore. @@ -905,7 +905,7 @@ mod tests { let solution = RawSolution:: { score: [5, 0, 0], ..Default::default() }; - let call = Call::submit_unsigned(solution.clone(), witness()); + let call = Call::submit_unsigned(Box::new(solution.clone()), witness()); assert_eq!( ::validate_unsigned( @@ -931,7 +931,7 @@ mod tests { // This is in itself an invalid BS solution. let solution = RawSolution:: { score: [5, 0, 0], ..Default::default() }; - let call = Call::submit_unsigned(solution.clone(), witness()); + let call = Call::submit_unsigned(Box::new(solution.clone()), witness()); let outer_call: OuterCall = call.into(); let _ = outer_call.dispatch(Origin::none()); }) @@ -951,7 +951,7 @@ mod tests { let mut correct_witness = witness(); correct_witness.voters += 1; correct_witness.targets -= 1; - let call = Call::submit_unsigned(solution.clone(), correct_witness); + let call = Call::submit_unsigned(Box::new(solution.clone()), correct_witness); let outer_call: OuterCall = call.into(); let _ = outer_call.dispatch(Origin::none()); }) @@ -972,7 +972,7 @@ mod tests { // ensure this solution is valid. assert!(MultiPhase::queued_solution().is_none()); - assert_ok!(MultiPhase::submit_unsigned(Origin::none(), solution, witness)); + assert_ok!(MultiPhase::submit_unsigned(Origin::none(), Box::new(solution), witness)); assert!(MultiPhase::queued_solution().is_some()); }) } @@ -1054,7 +1054,9 @@ mod tests { }; let (solution, witness) = MultiPhase::prepare_election_result(result).unwrap(); assert_ok!(MultiPhase::unsigned_pre_dispatch_checks(&solution)); - assert_ok!(MultiPhase::submit_unsigned(Origin::none(), solution, witness)); + assert_ok!( + MultiPhase::submit_unsigned(Origin::none(), Box::new(solution), witness) + ); assert_eq!(MultiPhase::queued_solution().unwrap().score[0], 10); // trial 1: a solution who's score is only 2, i.e. 20% better in the first element. @@ -1096,7 +1098,9 @@ mod tests { // and it is fine assert_ok!(MultiPhase::unsigned_pre_dispatch_checks(&solution)); - assert_ok!(MultiPhase::submit_unsigned(Origin::none(), solution, witness)); + assert_ok!( + MultiPhase::submit_unsigned(Origin::none(), Box::new(solution), witness) + ); }) } From 5c687e1cb5ef65d07779e2d7930302a851dd4bb8 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Thu, 22 Jul 2021 15:43:02 +0200 Subject: [PATCH 3/9] WIP --- frame/grandpa/src/equivocation.rs | 5 ++++- frame/grandpa/src/lib.rs | 8 ++++---- frame/grandpa/src/tests.rs | 26 ++++++++++++++------------ frame/identity/src/benchmarking.rs | 16 ++++++++-------- frame/identity/src/lib.rs | 6 +++--- frame/identity/src/tests.rs | 28 ++++++++++++++-------------- 6 files changed, 47 insertions(+), 42 deletions(-) diff --git a/frame/grandpa/src/equivocation.rs b/frame/grandpa/src/equivocation.rs index 2ef106817c3e1..53f48c004747c 100644 --- a/frame/grandpa/src/equivocation.rs +++ b/frame/grandpa/src/equivocation.rs @@ -164,7 +164,10 @@ where ) -> DispatchResult { use frame_system::offchain::SubmitTransaction; - let call = Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof); + let call = Call::report_equivocation_unsigned( + Box::new(equivocation_proof), + key_owner_proof, + ); match SubmitTransaction::>::submit_unsigned_transaction(call.into()) { Ok(()) => log::info!( diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 184ab49608747..c05157b48db31 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -186,12 +186,12 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::report_equivocation(key_owner_proof.validator_count()))] pub fn report_equivocation( origin: OriginFor, - equivocation_proof: EquivocationProof, + equivocation_proof: Box>, key_owner_proof: T::KeyOwnerProof, ) -> DispatchResultWithPostInfo { let reporter = ensure_signed(origin)?; - Self::do_report_equivocation(Some(reporter), equivocation_proof, key_owner_proof) + Self::do_report_equivocation(Some(reporter), *equivocation_proof, key_owner_proof) } /// Report voter equivocation/misbehavior. This method will verify the @@ -206,14 +206,14 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::report_equivocation(key_owner_proof.validator_count()))] pub fn report_equivocation_unsigned( origin: OriginFor, - equivocation_proof: EquivocationProof, + equivocation_proof: Box>, key_owner_proof: T::KeyOwnerProof, ) -> DispatchResultWithPostInfo { ensure_none(origin)?; Self::do_report_equivocation( T::HandleEquivocation::block_author(), - equivocation_proof, + *equivocation_proof, key_owner_proof, ) } diff --git a/frame/grandpa/src/tests.rs b/frame/grandpa/src/tests.rs index 2439c8c819576..66193f0a6deae 100644 --- a/frame/grandpa/src/tests.rs +++ b/frame/grandpa/src/tests.rs @@ -354,7 +354,7 @@ fn report_equivocation_current_set_works() { // report the equivocation and the tx should be dispatched successfully assert_ok!(Grandpa::report_equivocation_unsigned( Origin::none(), - equivocation_proof, + Box::new(equivocation_proof), key_owner_proof, ),); @@ -432,7 +432,7 @@ fn report_equivocation_old_set_works() { // the old set, the tx should be dispatched successfully assert_ok!(Grandpa::report_equivocation_unsigned( Origin::none(), - equivocation_proof, + Box::new(equivocation_proof), key_owner_proof, ),); @@ -495,7 +495,7 @@ fn report_equivocation_invalid_set_id() { assert_err!( Grandpa::report_equivocation_unsigned( Origin::none(), - equivocation_proof, + Box::new(equivocation_proof), key_owner_proof, ), Error::::InvalidEquivocationProof, @@ -536,7 +536,7 @@ fn report_equivocation_invalid_session() { assert_err!( Grandpa::report_equivocation_unsigned( Origin::none(), - equivocation_proof, + Box::new(equivocation_proof), key_owner_proof, ), Error::::InvalidEquivocationProof, @@ -581,7 +581,7 @@ fn report_equivocation_invalid_key_owner_proof() { assert_err!( Grandpa::report_equivocation_unsigned( Origin::none(), - equivocation_proof, + Box::new(equivocation_proof), invalid_key_owner_proof, ), Error::::InvalidKeyOwnershipProof, @@ -612,7 +612,7 @@ fn report_equivocation_invalid_equivocation_proof() { assert_err!( Grandpa::report_equivocation_unsigned( Origin::none(), - equivocation_proof, + Box::new(equivocation_proof), key_owner_proof.clone(), ), Error::::InvalidEquivocationProof, @@ -681,8 +681,10 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() { let key_owner_proof = Historical::prove((sp_finality_grandpa::KEY_TYPE, &equivocation_key)).unwrap(); - let call = - Call::report_equivocation_unsigned(equivocation_proof.clone(), key_owner_proof.clone()); + let call = Call::report_equivocation_unsigned( + Box::new(equivocation_proof.clone()), + key_owner_proof.clone(), + ); // only local/inblock reports are allowed assert_eq!( @@ -714,7 +716,7 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() { assert_ok!(::pre_dispatch(&call)); // we submit the report - Grandpa::report_equivocation_unsigned(Origin::none(), equivocation_proof, key_owner_proof) + Grandpa::report_equivocation_unsigned(Origin::none(), Box::new(equivocation_proof), key_owner_proof) .unwrap(); // the report should now be considered stale and the transaction is invalid @@ -838,7 +840,7 @@ fn valid_equivocation_reports_dont_pay_fees() { // check the dispatch info for the call. let info = Call::::report_equivocation_unsigned( - equivocation_proof.clone(), + Box::new(equivocation_proof.clone()), key_owner_proof.clone(), ) .get_dispatch_info(); @@ -850,7 +852,7 @@ fn valid_equivocation_reports_dont_pay_fees() { // report the equivocation. let post_info = Grandpa::report_equivocation_unsigned( Origin::none(), - equivocation_proof.clone(), + Box::new(equivocation_proof.clone()), key_owner_proof.clone(), ) .unwrap(); @@ -864,7 +866,7 @@ fn valid_equivocation_reports_dont_pay_fees() { // duplicate. let post_info = Grandpa::report_equivocation_unsigned( Origin::none(), - equivocation_proof, + Box::new(equivocation_proof), key_owner_proof, ) .err() diff --git a/frame/identity/src/benchmarking.rs b/frame/identity/src/benchmarking.rs index 77b64c68fd7c0..8bda24ddc73e1 100644 --- a/frame/identity/src/benchmarking.rs +++ b/frame/identity/src/benchmarking.rs @@ -77,7 +77,7 @@ fn create_sub_accounts( // Set identity so `set_subs` does not fail. let _ = T::Currency::make_free_balance_be(&who, BalanceOf::::max_value()); let info = create_identity_info::(1); - Identity::::set_identity(who_origin.clone().into(), info)?; + Identity::::set_identity(who_origin.clone().into(), Box::new(info))?; Ok(subs) } @@ -137,7 +137,7 @@ benchmarks! { // Add an initial identity let initial_info = create_identity_info::(1); - Identity::::set_identity(caller_origin.clone(), initial_info)?; + Identity::::set_identity(caller_origin.clone(), Box::new(initial_info))?; // User requests judgement from all the registrars, and they approve for i in 0..r { @@ -151,7 +151,7 @@ benchmarks! { } caller }; - }: _(RawOrigin::Signed(caller.clone()), create_identity_info::(x)) + }: _(RawOrigin::Signed(caller.clone()), Box::new(create_identity_info::(x))) verify { assert_last_event::(Event::::IdentitySet(caller).into()); } @@ -204,7 +204,7 @@ benchmarks! { let info = create_identity_info::(x); let caller: T::AccountId = whitelisted_caller(); let caller_origin = ::Origin::from(RawOrigin::Signed(caller)); - Identity::::set_identity(caller_origin, info)?; + Identity::::set_identity(caller_origin, Box::new(info))?; }; // User requests judgement from all the registrars, and they approve @@ -233,7 +233,7 @@ benchmarks! { let info = create_identity_info::(x); let caller: T::AccountId = whitelisted_caller(); let caller_origin = ::Origin::from(RawOrigin::Signed(caller)); - Identity::::set_identity(caller_origin, info)?; + Identity::::set_identity(caller_origin, Box::new(info))?; }; }: _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into()) verify { @@ -251,7 +251,7 @@ benchmarks! { let info = create_identity_info::(x); let caller: T::AccountId = whitelisted_caller(); let caller_origin = ::Origin::from(RawOrigin::Signed(caller)); - Identity::::set_identity(caller_origin, info)?; + Identity::::set_identity(caller_origin, Box::new(info))?; }; Identity::::request_judgement(caller_origin, r - 1, 10u32.into())?; @@ -321,7 +321,7 @@ benchmarks! { let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; let x in 1 .. T::MaxAdditionalFields::get() => { let info = create_identity_info::(x); - Identity::::set_identity(user_origin.clone(), info)?; + Identity::::set_identity(user_origin.clone(), Box::new(info))?; }; Identity::::add_registrar(RawOrigin::Root.into(), caller.clone())?; @@ -342,7 +342,7 @@ benchmarks! { let _ = T::Currency::make_free_balance_be(&target, BalanceOf::::max_value()); let info = create_identity_info::(x); - Identity::::set_identity(target_origin.clone(), info)?; + Identity::::set_identity(target_origin.clone(), Box::new(info))?; let _ = add_sub_accounts::(&target, s)?; // User requests judgement from all the registrars, and they approve diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index 7b401d95573f6..8b5eb3367ac5f 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -335,7 +335,7 @@ pub mod pallet { ))] pub fn set_identity( origin: OriginFor, - info: IdentityInfo, + info: Box>, ) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; let extra_fields = info.additional.len() as u32; @@ -346,11 +346,11 @@ pub mod pallet { Some(mut id) => { // Only keep non-positive judgements. id.judgements.retain(|j| j.1.is_sticky()); - id.info = info; + id.info = *info; id }, None => - Registration { info, judgements: BoundedVec::default(), deposit: Zero::zero() }, + Registration { info: *info, judgements: BoundedVec::default(), deposit: Zero::zero() }, }; let old_deposit = id.deposit; diff --git a/frame/identity/src/tests.rs b/frame/identity/src/tests.rs index 127b0a9ecb171..3e1219ad64f2e 100644 --- a/frame/identity/src/tests.rs +++ b/frame/identity/src/tests.rs @@ -150,7 +150,7 @@ fn editing_subaccounts_should_work() { assert_noop!(Identity::add_sub(Origin::signed(10), 20, data(1)), Error::::NoIdentity); - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten()))); // first sub account assert_ok!(Identity::add_sub(Origin::signed(10), 1, data(1))); @@ -195,8 +195,8 @@ fn resolving_subaccount_ownership_works() { new_test_ext().execute_with(|| { let data = |x| Data::Raw(vec![x; 1].try_into().unwrap()); - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); - assert_ok!(Identity::set_identity(Origin::signed(20), twenty())); + assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten()))); + assert_ok!(Identity::set_identity(Origin::signed(20), Box::new(twenty()))); // 10 claims 1 as a subaccount assert_ok!(Identity::add_sub(Origin::signed(10), 1, data(1))); @@ -266,7 +266,7 @@ fn registration_should_work() { three_fields.additional.try_push(Default::default()).unwrap(); three_fields.additional.try_push(Default::default()).unwrap(); assert_eq!(three_fields.additional.try_push(Default::default()), Err(())); - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten()))); assert_eq!(Identity::identity(10).unwrap().info, ten()); assert_eq!(Balances::free_balance(10), 90); assert_ok!(Identity::clear_identity(Origin::signed(10))); @@ -289,7 +289,7 @@ fn uninvited_judgement_should_work() { Error::::InvalidTarget ); - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten()))); assert_noop!( Identity::provide_judgement(Origin::signed(10), 0, 10, Judgement::Reasonable), Error::::InvalidIndex @@ -308,7 +308,7 @@ fn uninvited_judgement_should_work() { fn clearing_judgement_should_work() { new_test_ext().execute_with(|| { assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten()))); assert_ok!(Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Reasonable)); assert_ok!(Identity::clear_identity(Origin::signed(10))); assert_eq!(Identity::identity(10), None); @@ -318,7 +318,7 @@ fn clearing_judgement_should_work() { #[test] fn killing_slashing_should_work() { new_test_ext().execute_with(|| { - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten()))); assert_noop!(Identity::kill_identity(Origin::signed(1), 10), BadOrigin); assert_ok!(Identity::kill_identity(Origin::signed(2), 10)); assert_eq!(Identity::identity(10), None); @@ -333,7 +333,7 @@ fn setting_subaccounts_should_work() { let mut subs = vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]; assert_noop!(Identity::set_subs(Origin::signed(10), subs.clone()), Error::::NotFound); - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten()))); assert_ok!(Identity::set_subs(Origin::signed(10), subs.clone())); assert_eq!(Balances::free_balance(10), 80); assert_eq!(Identity::subs_of(10), (10, vec![20].try_into().unwrap())); @@ -374,7 +374,7 @@ fn setting_subaccounts_should_work() { #[test] fn clearing_account_should_remove_subaccounts_and_refund() { new_test_ext().execute_with(|| { - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten()))); assert_ok!(Identity::set_subs( Origin::signed(10), vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))] @@ -388,7 +388,7 @@ fn clearing_account_should_remove_subaccounts_and_refund() { #[test] fn killing_account_should_remove_subaccounts_and_not_refund() { new_test_ext().execute_with(|| { - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten()))); assert_ok!(Identity::set_subs( Origin::signed(10), vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))] @@ -405,7 +405,7 @@ fn cancelling_requested_judgement_should_work() { assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); assert_noop!(Identity::cancel_request(Origin::signed(10), 0), Error::::NoIdentity); - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten()))); assert_ok!(Identity::request_judgement(Origin::signed(10), 0, 10)); assert_ok!(Identity::cancel_request(Origin::signed(10), 0)); assert_eq!(Balances::free_balance(10), 90); @@ -424,7 +424,7 @@ fn requesting_judgement_should_work() { new_test_ext().execute_with(|| { assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_identity(Origin::signed(10), Box::new(ten()))); assert_noop!( Identity::request_judgement(Origin::signed(10), 0, 9), Error::::FeeChanged @@ -465,7 +465,7 @@ fn field_deposit_should_work() { assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); assert_ok!(Identity::set_identity( Origin::signed(10), - IdentityInfo { + Box::new(IdentityInfo { additional: vec![ ( Data::Raw(b"number".to_vec().try_into().unwrap()), @@ -479,7 +479,7 @@ fn field_deposit_should_work() { .try_into() .unwrap(), ..Default::default() - } + }) )); assert_eq!(Balances::free_balance(10), 70); }); From 769220d6ff49cbbe6fa1b2319e58a61b4d0b3ecf Mon Sep 17 00:00:00 2001 From: thiolliere Date: Thu, 22 Jul 2021 16:36:04 +0200 Subject: [PATCH 4/9] add some tests and limit --- bin/node/runtime/src/lib.rs | 10 ++++++++++ frame/identity/Cargo.toml | 6 +++++- frame/utility/src/lib.rs | 29 +++++++++++++++++++++++++++-- frame/utility/src/tests.rs | 12 ++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index f18836f2d6077..faf2c7a7ea956 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1671,4 +1671,14 @@ mod tests { is_submit_signed_transaction::(); } + + #[test] + fn call_size() { + assert!( + core::mem::size_of::() <= 200, + "size of Call is more than 200: some calls have too big arguments, use Box to reduce the + size of Call. + If the limit is too strong, maybe consider increase the limit to 300.", + ); + } } diff --git a/frame/identity/Cargo.toml b/frame/identity/Cargo.toml index b04594b737803..489a01b27da69 100644 --- a/frame/identity/Cargo.toml +++ b/frame/identity/Cargo.toml @@ -37,5 +37,9 @@ std = [ "frame-support/std", "frame-system/std", ] -runtime-benchmarks = ["frame-benchmarking"] +runtime-benchmarks = [ + "frame-benchmarking", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", +] try-runtime = ["frame-support/try-runtime"] diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index 1133bd8698574..93054702661b4 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -110,13 +110,33 @@ pub mod pallet { BatchCompleted, } + #[pallet::extra_constants] + impl Pallet { + /// The limit on the number of batched calls. + fn batched_calls_limit() -> u32 { + let allocator_limit = 33554432; // 32MiB + let call_size = core::mem::size_of::<::Call>() as u32; + // The margin to take into account vec doubling capacity. + let margin_factor = 3; + + allocator_limit / margin_factor / call_size + } + } + + #[pallet::error] + pub enum Error { + /// Too many calls batched. + TooManyCalls + } + #[pallet::call] impl Pallet { /// Send a batch of dispatch calls. /// /// May be called from any origin. /// - /// - `calls`: The calls to be dispatched from the same origin. + /// - `calls`: The calls to be dispatched from the same origin. The number of call must not + /// exceed the constant: `batched_calls_limit` (available in constant metadata). /// /// If origin is root then call are dispatch without checking origin filter. (This includes /// bypassing `frame_system::Config::BaseCallFilter`). @@ -154,6 +174,8 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let is_root = ensure_root(origin.clone()).is_ok(); let calls_len = calls.len(); + ensure!(calls_len <= Self::batched_calls_limit() as usize, Error::::TooManyCalls); + // Track the actual weight of each of the batch calls. let mut weight: Weight = 0; for (index, call) in calls.into_iter().enumerate() { @@ -231,7 +253,8 @@ pub mod pallet { /// /// May be called from any origin. /// - /// - `calls`: The calls to be dispatched from the same origin. + /// - `calls`: The calls to be dispatched from the same origin. The number of call must not + /// exceed the constant: `batched_calls_limit` (available in constant metadata). /// /// If origin is root then call are dispatch without checking origin filter. (This includes /// bypassing `frame_system::Config::BaseCallFilter`). @@ -264,6 +287,8 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let is_root = ensure_root(origin.clone()).is_ok(); let calls_len = calls.len(); + ensure!(calls_len <= Self::batched_calls_limit() as usize, Error::::TooManyCalls); + // Track the actual weight of each of the batch calls. let mut weight: Weight = 0; for (index, call) in calls.into_iter().enumerate() { diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 61890972d3a03..fdc738bcded93 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -66,6 +66,9 @@ pub mod example { Ok(end_weight.into()) } } + + #[weight = 0] + fn big_variant(_origin, _arg: [u8; 400]) {} } } } @@ -588,3 +591,12 @@ fn batch_all_does_not_nest() { assert_eq!(Balances::free_balance(2), 10); }); } + +#[test] +fn batch_limit() { + new_test_ext().execute_with(|| { + let calls = vec![Call::System(SystemCall::remark(vec![])); 40_000]; + assert_noop!(Utility::batch(Origin::signed(1), calls.clone()), Error::::TooManyCalls); + assert_noop!(Utility::batch_all(Origin::signed(1), calls), Error::::TooManyCalls); + }); +} From 052a68558045c95c68dc6fd13e4977903e810a46 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Thu, 22 Jul 2021 16:38:58 +0200 Subject: [PATCH 5/9] remove wip test --- bin/node/runtime/src/lib.rs | 45 ------------------------------------- 1 file changed, 45 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index faf2c7a7ea956..5c64d6ba41825 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1176,51 +1176,6 @@ impl pallet_transaction_storage::Config for Runtime { type WeightInfo = pallet_transaction_storage::weights::SubstrateWeight; } -#[test] -fn foo() { - println!("System{}", std::mem::size_of::>()); - println!("Utility{}", std::mem::size_of::>()); - println!("Babe{}", std::mem::size_of::>()); - println!("Timestamp{}", std::mem::size_of::>()); - println!("Authorship{}", std::mem::size_of::>()); - println!("Indices{}", std::mem::size_of::>()); - println!("Balances{}", std::mem::size_of::>()); - println!("TransactionPayment{}", std::mem::size_of::>()); - println!("ElectionProviderMultiPhase{}", std::mem::size_of::>()); - println!("Staking{}", std::mem::size_of::>()); - println!("Session{}", std::mem::size_of::>()); - println!("Democracy{}", std::mem::size_of::>()); - println!("Council{}", std::mem::size_of::>()); - println!("TechnicalCommittee{}", std::mem::size_of::>()); - println!("Elections{}", std::mem::size_of::>()); - println!("TechnicalMembership{}", std::mem::size_of::>()); - println!("Grandpa{}", std::mem::size_of::>()); - println!("Treasury{}", std::mem::size_of::>()); - println!("Contracts{}", std::mem::size_of::>()); - println!("Sudo{}", std::mem::size_of::>()); - println!("ImOnline{}", std::mem::size_of::>()); - println!("AuthorityDiscovery{}", std::mem::size_of::>()); - println!("Offences{}", std::mem::size_of::>()); - println!("Historical{}", std::mem::size_of::>()); - println!("RandomnessCollectiveFlip{}", std::mem::size_of::>()); - println!("Identity{}", std::mem::size_of::>()); - println!("Society{}", std::mem::size_of::>()); - println!("Recovery{}", std::mem::size_of::>()); - println!("Vesting{}", std::mem::size_of::>()); - println!("Scheduler{}", std::mem::size_of::>()); - println!("Proxy{}", std::mem::size_of::>()); - println!("Multisig{}", std::mem::size_of::>()); - println!("Bounties{}", std::mem::size_of::>()); - println!("Tips{}", std::mem::size_of::>()); - println!("Assets{}", std::mem::size_of::>()); - println!("Mmr{}", std::mem::size_of::>()); - println!("Lottery{}", std::mem::size_of::>()); - println!("Gilt{}", std::mem::size_of::>()); - println!("Uniques{}", std::mem::size_of::>()); - println!("TransactionStorage{}", std::mem::size_of::>()); - panic!(); -} - construct_runtime!( pub enum Runtime where Block = Block, From 6fcc87543e73ec2938029d6405987e51b0512aea Mon Sep 17 00:00:00 2001 From: thiolliere Date: Thu, 22 Jul 2021 16:40:46 +0200 Subject: [PATCH 6/9] fmt --- frame/babe/src/equivocation.rs | 6 ++---- frame/babe/src/tests.rs | 14 +++++++------- .../src/benchmarking.rs | 5 ++++- .../src/unsigned.rs | 18 +++++++++++------- frame/grandpa/src/equivocation.rs | 6 ++---- frame/grandpa/src/tests.rs | 8 ++++++-- frame/identity/src/lib.rs | 7 +++++-- frame/utility/src/lib.rs | 2 +- 8 files changed, 38 insertions(+), 28 deletions(-) diff --git a/frame/babe/src/equivocation.rs b/frame/babe/src/equivocation.rs index 2d0cc6c2c26a7..2558ca8a6e255 100644 --- a/frame/babe/src/equivocation.rs +++ b/frame/babe/src/equivocation.rs @@ -155,10 +155,8 @@ where ) -> DispatchResult { use frame_system::offchain::SubmitTransaction; - let call = Call::report_equivocation_unsigned( - Box::new(equivocation_proof), - key_owner_proof, - ); + let call = + Call::report_equivocation_unsigned(Box::new(equivocation_proof), key_owner_proof); match SubmitTransaction::>::submit_unsigned_transaction(call.into()) { Ok(()) => log::info!( diff --git a/frame/babe/src/tests.rs b/frame/babe/src/tests.rs index 8b3a00ee33ce5..b5e1a02df807f 100644 --- a/frame/babe/src/tests.rs +++ b/frame/babe/src/tests.rs @@ -420,7 +420,7 @@ fn report_equivocation_current_session_works() { Box::new(equivocation_proof), key_owner_proof, ) - .unwrap(); + .unwrap(); // start a new era so that the results of the offence report // are applied at era end @@ -492,7 +492,7 @@ fn report_equivocation_old_session_works() { Box::new(equivocation_proof), key_owner_proof, ) - .unwrap(); + .unwrap(); // start a new era so that the results of the offence report // are applied at era end @@ -738,9 +738,9 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() { Babe::report_equivocation_unsigned( Origin::none(), Box::new(equivocation_proof), - key_owner_proof + key_owner_proof, ) - .unwrap(); + .unwrap(); // the report should now be considered stale and the transaction is invalid. // the check for staleness should be done on both `validate_unsigned` and on `pre_dispatch` @@ -827,9 +827,9 @@ fn valid_equivocation_reports_dont_pay_fees() { Box::new(equivocation_proof), key_owner_proof, ) - .err() - .unwrap() - .post_info; + .err() + .unwrap() + .post_info; // the fee is not waived and the original weight is kept. assert!(post_info.actual_weight.is_none()); diff --git a/frame/election-provider-multi-phase/src/benchmarking.rs b/frame/election-provider-multi-phase/src/benchmarking.rs index 5c8a42baf4d52..cc7d99a854946 100644 --- a/frame/election-provider-multi-phase/src/benchmarking.rs +++ b/frame/election-provider-multi-phase/src/benchmarking.rs @@ -26,7 +26,10 @@ use rand::{prelude::SliceRandom, rngs::SmallRng, SeedableRng}; use sp_arithmetic::{per_things::Percent, traits::One}; use sp_npos_elections::IndexAssignment; use sp_runtime::InnerOf; -use sp_std::{convert::{TryFrom, TryInto}, boxed::Box}; +use sp_std::{ + boxed::Box, + convert::{TryFrom, TryInto}, +}; const SEED: u32 = 999; diff --git a/frame/election-provider-multi-phase/src/unsigned.rs b/frame/election-provider-multi-phase/src/unsigned.rs index 0c46ea8eaa646..41f8ced0ce827 100644 --- a/frame/election-provider-multi-phase/src/unsigned.rs +++ b/frame/election-provider-multi-phase/src/unsigned.rs @@ -34,7 +34,7 @@ use sp_runtime::{ traits::TrailingZeroInput, DispatchError, SaturatedConversion, }; -use sp_std::{cmp::Ordering, convert::TryFrom, vec::Vec, boxed::Box}; +use sp_std::{boxed::Box, cmp::Ordering, convert::TryFrom, vec::Vec}; /// Storage key used to store the last block number at which offchain worker ran. pub(crate) const OFFCHAIN_LAST_BLOCK: &[u8] = b"parity/multi-phase-unsigned-election"; @@ -1054,9 +1054,11 @@ mod tests { }; let (solution, witness) = MultiPhase::prepare_election_result(result).unwrap(); assert_ok!(MultiPhase::unsigned_pre_dispatch_checks(&solution)); - assert_ok!( - MultiPhase::submit_unsigned(Origin::none(), Box::new(solution), witness) - ); + assert_ok!(MultiPhase::submit_unsigned( + Origin::none(), + Box::new(solution), + witness + )); assert_eq!(MultiPhase::queued_solution().unwrap().score[0], 10); // trial 1: a solution who's score is only 2, i.e. 20% better in the first element. @@ -1098,9 +1100,11 @@ mod tests { // and it is fine assert_ok!(MultiPhase::unsigned_pre_dispatch_checks(&solution)); - assert_ok!( - MultiPhase::submit_unsigned(Origin::none(), Box::new(solution), witness) - ); + assert_ok!(MultiPhase::submit_unsigned( + Origin::none(), + Box::new(solution), + witness + )); }) } diff --git a/frame/grandpa/src/equivocation.rs b/frame/grandpa/src/equivocation.rs index 53f48c004747c..40d8535dabb60 100644 --- a/frame/grandpa/src/equivocation.rs +++ b/frame/grandpa/src/equivocation.rs @@ -164,10 +164,8 @@ where ) -> DispatchResult { use frame_system::offchain::SubmitTransaction; - let call = Call::report_equivocation_unsigned( - Box::new(equivocation_proof), - key_owner_proof, - ); + let call = + Call::report_equivocation_unsigned(Box::new(equivocation_proof), key_owner_proof); match SubmitTransaction::>::submit_unsigned_transaction(call.into()) { Ok(()) => log::info!( diff --git a/frame/grandpa/src/tests.rs b/frame/grandpa/src/tests.rs index 66193f0a6deae..034758e0a21b5 100644 --- a/frame/grandpa/src/tests.rs +++ b/frame/grandpa/src/tests.rs @@ -716,8 +716,12 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() { assert_ok!(::pre_dispatch(&call)); // we submit the report - Grandpa::report_equivocation_unsigned(Origin::none(), Box::new(equivocation_proof), key_owner_proof) - .unwrap(); + Grandpa::report_equivocation_unsigned( + Origin::none(), + Box::new(equivocation_proof), + key_owner_proof, + ) + .unwrap(); // the report should now be considered stale and the transaction is invalid // the check for staleness should be done on both `validate_unsigned` and on `pre_dispatch` diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index 8b5eb3367ac5f..19251cfbb85f2 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -349,8 +349,11 @@ pub mod pallet { id.info = *info; id }, - None => - Registration { info: *info, judgements: BoundedVec::default(), deposit: Zero::zero() }, + None => Registration { + info: *info, + judgements: BoundedVec::default(), + deposit: Zero::zero(), + }, }; let old_deposit = id.deposit; diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index 93054702661b4..8d21214ce5ae0 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -126,7 +126,7 @@ pub mod pallet { #[pallet::error] pub enum Error { /// Too many calls batched. - TooManyCalls + TooManyCalls, } #[pallet::call] From b09fdaff9f332958611155918e7d38d395d8d875 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Fri, 23 Jul 2021 12:07:19 +0200 Subject: [PATCH 7/9] Update bin/node/runtime/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- bin/node/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 5c64d6ba41825..1907ddcc492fd 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1631,7 +1631,7 @@ mod tests { fn call_size() { assert!( core::mem::size_of::() <= 200, - "size of Call is more than 200: some calls have too big arguments, use Box to reduce the + "size of Call is more than 200 bytes: some calls have too big arguments, use Box to reduce the size of Call. If the limit is too strong, maybe consider increase the limit to 300.", ); From bdff65a76709053e97fd8a78eea35f8e511cb1b5 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Tue, 27 Jul 2021 10:22:20 +0200 Subject: [PATCH 8/9] fmt --- frame/election-provider-multi-phase/src/lib.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/frame/election-provider-multi-phase/src/lib.rs b/frame/election-provider-multi-phase/src/lib.rs index 7cb37fcf0eea3..a115d12c8ad27 100644 --- a/frame/election-provider-multi-phase/src/lib.rs +++ b/frame/election-provider-multi-phase/src/lib.rs @@ -982,12 +982,8 @@ pub mod pallet { T::SignedRewardBase::get().saturating_add(call_fee) }; - let submission = SignedSubmission { - who: who.clone(), - deposit, - solution: *solution, - reward, - }; + let submission = + SignedSubmission { who: who.clone(), deposit, solution: *solution, reward }; // insert the submission if the queue has space or it's better than the weakest // eject the weakest if the queue was full From 57cd378c9251ea9f1e256d18812ec27be5e6c44f Mon Sep 17 00:00:00 2001 From: thiolliere Date: Tue, 27 Jul 2021 17:02:46 +0200 Subject: [PATCH 9/9] use primitives allocation limit --- frame/utility/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index 8d21214ce5ae0..22bbb589d6be7 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -114,7 +114,7 @@ pub mod pallet { impl Pallet { /// The limit on the number of batched calls. fn batched_calls_limit() -> u32 { - let allocator_limit = 33554432; // 32MiB + let allocator_limit = sp_core::MAX_POSSIBLE_ALLOCATION; let call_size = core::mem::size_of::<::Call>() as u32; // The margin to take into account vec doubling capacity. let margin_factor = 3;