From dd0dcf48b849d2a6906959067609b484679a836b Mon Sep 17 00:00:00 2001 From: Yeou Date: Tue, 19 Sep 2023 17:04:22 +0800 Subject: [PATCH] remove unused code and comments --- node/Cargo.toml | 8 ----- runtime/src/constants.rs | 59 -------------------------------- runtime/src/lib.rs | 73 ++++++++++++++++++++++------------------ 3 files changed, 41 insertions(+), 99 deletions(-) delete mode 100755 runtime/src/constants.rs diff --git a/node/Cargo.toml b/node/Cargo.toml index 027842bb..e60f60f8 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -38,9 +38,7 @@ sp-inherents = { version = "4.0.0-dev", git = "https://github.com/CESSProject/su sp-keyring = { version = "7.0.0", git = "https://github.com/CESSProject/substrate.git", branch = "cess-polkadot-v0.9.36" } sp-keystore = { version = "0.13.0", git = "https://github.com/CESSProject/substrate.git", branch = "cess-polkadot-v0.9.36" } sp-consensus = { version = "0.10.0-dev", git = "https://github.com/CESSProject/substrate.git", branch = "cess-polkadot-v0.9.36" } -# sp-transaction-pool sp-transaction-storage-proof = { version = "4.0.0-dev", git = "https://github.com/CESSProject/substrate.git", branch = "cess-polkadot-v0.9.36" } -# sp-io # client dependencies sc-client-api = { version = "4.0.0-dev", git = "https://github.com/CESSProject/substrate.git", branch = "cess-polkadot-v0.9.36" } @@ -65,21 +63,15 @@ sc-sysinfo = { version = "6.0.0-dev", git = "https://github.com/CESSProject/subs # frame dependencies frame-system = { version = "4.0.0-dev", git = "https://github.com/CESSProject/substrate.git", branch = "cess-polkadot-v0.9.36" } -# frame-system-rpc-runtime-api = { version = "4.0.0-dev", git = "https://github.com/CESSProject/substrate.git", branch = "cess-polkadot-v0.9.36" } pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/CESSProject/substrate.git", branch = "cess-polkadot-v0.9.36" } -# pallet-assets -# pallet-asset-tx-payment pallet-im-online = { version = "4.0.0-dev", git = "https://github.com/CESSProject/substrate.git", branch = "cess-polkadot-v0.9.36" } # node-specific dependencies cess-node-runtime = { path = "../runtime" } -# node-rpc -# node-primitives # CLI-specific dependencies sc-cli = { version = "0.10.0-dev", git = "https://github.com/CESSProject/substrate.git", branch = "cess-polkadot-v0.9.36" } frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/CESSProject/substrate.git", branch = "cess-polkadot-v0.9.36" } -# node-inspect try-runtime-cli = { version = "0.10.0-dev", optional = true, git = "https://github.com/CESSProject/substrate.git", branch = "cess-polkadot-v0.9.36" } serde_json = "1.0.85" diff --git a/runtime/src/constants.rs b/runtime/src/constants.rs deleted file mode 100755 index 42ee46d1..00000000 --- a/runtime/src/constants.rs +++ /dev/null @@ -1,59 +0,0 @@ -pub mod currency { - /// Balance of an account. - pub type Balance = u128; - - pub const MILLICENTS: Balance = 1_000_000_000; - pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent. - pub const DOLLARS: Balance = 100 * CENTS; - - pub const fn deposit(items: u32, bytes: u32) -> Balance { - items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS - } -} - -/// Time. -pub mod time { - pub type BlockNumber = u32; - pub type Moment = u64; - - /// Since BABE is probabilistic this is the average expected block time that - /// we are targeting. Blocks will be produced at a minimum duration defined - /// by `SLOT_DURATION`, but some slots will not be allocated to any - /// authority and hence no block will be produced. We expect to have this - /// block time on average following the defined slot duration and the value - /// of `c` configured for BABE (where `1 - c` represents the probability of - /// a slot being empty). - /// This value is only used indirectly to define the unit constants below - /// that are expressed in blocks. The rest of the code should use - /// `SLOT_DURATION` instead (like the Timestamp pallet for calculating the - /// minimum period). - /// - /// If using BABE with secondary slots (default) then all of the slots will - /// always be assigned, in which case `MILLISECS_PER_BLOCK` and - /// `SLOT_DURATION` should have the same value. - /// - /// - pub const MILLISECS_PER_BLOCK: Moment = 3000; - pub const SECS_PER_BLOCK: Moment = MILLISECS_PER_BLOCK / 1000; - - // NOTE: Currently it is not possible to change the slot duration after the chain has started. - // Attempting to do so will brick block production. - pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; - - // 1 in 4 blocks (on average, not counting collisions) will be primary BABE blocks. - pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4); - - // NOTE: Currently it is not possible to change the epoch duration after the chain has started. - // Attempting to do so will brick block production. - pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 10 * MINUTES; - pub const EPOCH_DURATION_IN_SLOTS: u64 = { - const SLOT_FILL_RATE: f64 = MILLISECS_PER_BLOCK as f64 / SLOT_DURATION as f64; - - (EPOCH_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as u64 - }; - - // These time units are defined in number of blocks. - pub const MINUTES: BlockNumber = 60 / (SECS_PER_BLOCK as BlockNumber); - pub const HOURS: BlockNumber = MINUTES * 60; - pub const DAYS: BlockNumber = HOURS * 24; -} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 88a16728..63ac3db6 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -16,18 +16,18 @@ pub fn wasm_binary_unwrap() -> &'static [u8] { ) } -use codec::{Decode, Encode, /*MaxEncodedLen*/}; -use frame_election_provider_support::{ - onchain, ExtendedBalance, ElectionDataProvider, VoteWeight -}; +use codec::{Decode, Encode}; +use cp_cess_common::FRAGMENT_COUNT; +use frame_election_provider_support::{onchain, ElectionDataProvider, ExtendedBalance, VoteWeight}; +pub use frame_system::Call as SystemCall; pub use pallet_file_bank; -pub use pallet_storage_handler; -pub use pallet_oss; use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, }; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; +pub use pallet_oss; use pallet_session::historical as pallet_session_historical; +pub use pallet_storage_handler; pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use sp_api::impl_runtime_apis; @@ -39,8 +39,9 @@ use sp_runtime::{ generic::Era, impl_opaque_keys, traits::{ - BlakeTwo256, Block as BlockT, Bounded, ConvertInto, Dispatchable, DispatchInfoOf, IdentifyAccount, NumberFor, - OpaqueKeys, PostDispatchInfoOf, SaturatedConversion, StaticLookup, Verify, + BlakeTwo256, Block as BlockT, Bounded, ConvertInto, DispatchInfoOf, Dispatchable, + IdentifyAccount, NumberFor, OpaqueKeys, PostDispatchInfoOf, SaturatedConversion, + StaticLookup, Verify, }, transaction_validity::{ TransactionPriority, TransactionSource, TransactionValidity, TransactionValidityError, @@ -48,9 +49,7 @@ use sp_runtime::{ ApplyExtrinsicResult, FixedPointNumber, MultiSignature, Perbill, Percent, Permill, Perquintill, RuntimeAppPublic, }; -use cp_cess_common::{FRAGMENT_COUNT}; use sp_std::{marker::PhantomData, prelude::*}; -pub use frame_system::Call as SystemCall; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; @@ -58,17 +57,19 @@ use sp_version::RuntimeVersion; // A few exports that help ease life for downstream crates. pub use frame_support::{ construct_runtime, + dispatch::DispatchClass, pallet_prelude::Get, parameter_types, - dispatch::DispatchClass, traits::{ AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32, ConstU8, Currency, CurrencyToVote, EitherOfDiverse, EqualPrivilegeOnly, Everything, FindAuthor, Imbalance, - InstanceFilter, KeyOwnerProofSystem, Nothing, - OnUnbalanced, Randomness, StorageInfo, U128CurrencyToVote, + InstanceFilter, KeyOwnerProofSystem, Nothing, OnUnbalanced, Randomness, StorageInfo, + U128CurrencyToVote, }, weights::{ - constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND}, + constants::{ + BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND, + }, ConstantMultiplier, IdentityFee, Weight, }, ConsensusEngineId, PalletId, StorageValue, @@ -81,11 +82,7 @@ use frame_system::{ pub mod impls; use impls::{Author, CreditToBlockAuthor, SchedulerStashAccountFinder}; -// use frame_support::traits::OnRuntimeUpgrade; -// pub use pallet_file_bank::migrations::TestMigrationFileBank; -// pub use pallet_audit::migrations::MigrationSegmentBook; -pub mod constants; use fp_rpc::TransactionStatus; pub use pallet_balances::Call as BalancesCall; use pallet_ethereum::{Call::transact, Transaction as EthereumTransaction}; @@ -274,7 +271,8 @@ parameter_types! { const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10); /// We allow for 2 seconds of compute with a 6 second average block time. -const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), u64::MAX); +const MAXIMUM_BLOCK_WEIGHT: Weight = + Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), u64::MAX); parameter_types! { pub RuntimeBlockLength: BlockLength = @@ -459,8 +457,6 @@ impl pallet_scheduler::Config for Runtime { type WeightInfo = pallet_scheduler::weights::SubstrateWeight; type OriginPrivilegeCmp = EqualPrivilegeOnly; type Preimages = Preimage; - // type PreimageProvider = Preimage; - // type NoPreimagePostponement = NoPreimagePostponement; } parameter_types! { @@ -770,7 +766,10 @@ pub struct OnChainVrfSloverConfig; impl pallet_rrsc::VrfSloverConfig for OnChainVrfSloverConfig { fn min_electable_weight() -> VoteWeight { let total_issuance = ::Currency::total_issuance(); - ::CurrencyToVote::to_vote(MIN_ELECTABLE_STAKE, total_issuance) + ::CurrencyToVote::to_vote( + MIN_ELECTABLE_STAKE, + total_issuance, + ) } } @@ -926,8 +925,13 @@ impl pallet_transaction_payment::Config for Runtime { type OperationalFeeMultiplier = OperationalFeeMultiplier; type WeightToFee = IdentityFee; type LengthToFee = ConstantMultiplier; - type FeeMultiplierUpdate = - TargetedFeeAdjustment; + type FeeMultiplierUpdate = TargetedFeeAdjustment< + Self, + TargetBlockFullness, + AdjustmentVariable, + MinimumMultiplier, + MaximumMultiplier, + >; } impl pallet_sudo::Config for Runtime { @@ -1125,7 +1129,10 @@ where public: ::Signer, account: AccountId, nonce: Index, - ) -> Option<(RuntimeCall, ::SignaturePayload)> { + ) -> Option<( + RuntimeCall, + ::SignaturePayload, + )> { let tip = 0; // take the biggest period possible. let period = @@ -1409,7 +1416,7 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall { } fn validate_self_contained( - &self, + &self, info: &Self::SignedInfo, dispatch_info: &DispatchInfoOf, len: usize, @@ -1420,7 +1427,6 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall { } } - fn pre_dispatch_self_contained( &self, info: &Self::SignedInfo, @@ -1428,7 +1434,8 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall { len: usize, ) -> Option> { match self { - RuntimeCall::Ethereum(call) => call.pre_dispatch_self_contained(info, dispatch_info, len), + RuntimeCall::Ethereum(call) => + call.pre_dispatch_self_contained(info, dispatch_info, len), _ => None, } } @@ -1438,9 +1445,10 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall { info: Self::SignedInfo, ) -> Option>> { match self { - call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => Some( - call.dispatch(RuntimeOrigin::from(pallet_ethereum::RawOrigin::EthereumTransaction(info))), - ), + call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => + Some(call.dispatch(RuntimeOrigin::from( + pallet_ethereum::RawOrigin::EthereumTransaction(info), + ))), _ => None, } } @@ -1565,7 +1573,8 @@ pub type SignedExtra = ( pub type UncheckedExtrinsic = fp_self_contained::UncheckedExtrinsic; /// Extrinsic type that has already been checked. -pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic; +pub type CheckedExtrinsic = + fp_self_contained::CheckedExtrinsic; /// The payload being signed in transactions. pub type SignedPayload = generic::SignedPayload; // Executive: handles dispatch to the various modules.