From 504914b0a6a3d959738a4b0d6f694bf0a61e68a3 Mon Sep 17 00:00:00 2001 From: Stanislav Tkach Date: Thu, 20 Feb 2020 18:03:33 +0200 Subject: [PATCH] Remove deprecated API (#4993) * Remove deprecated API * Remove (some) allow(dead_code) * Bump spec_version * Fix import, remove allow dead code. Co-authored-by: Shawn Tabrizi --- substrate/bin/node/cli/src/service.rs | 4 -- substrate/client/block-builder/src/lib.rs | 68 ++++++------------- substrate/client/consensus/babe/src/lib.rs | 43 ------------ substrate/frame/babe/src/lib.rs | 1 - substrate/frame/babe/src/mock.rs | 6 +- substrate/frame/babe/src/tests.rs | 4 +- substrate/frame/grandpa/src/lib.rs | 1 - substrate/primitives/block-builder/src/lib.rs | 27 -------- substrate/primitives/blockchain/src/error.rs | 13 ---- 9 files changed, 25 insertions(+), 142 deletions(-) diff --git a/substrate/bin/node/cli/src/service.rs b/substrate/bin/node/cli/src/service.rs index a882483a44..79e1f97169 100644 --- a/substrate/bin/node/cli/src/service.rs +++ b/substrate/bin/node/cli/src/service.rs @@ -264,9 +264,7 @@ macro_rules! new_full { }} } -#[allow(dead_code)] type ConcreteBlock = node_primitives::Block; -#[allow(dead_code)] type ConcreteClient = Client< Backend, @@ -275,9 +273,7 @@ type ConcreteClient = ConcreteBlock, node_runtime::RuntimeApi >; -#[allow(dead_code)] type ConcreteBackend = Backend; -#[allow(dead_code)] type ConcreteTransactionPool = sc_transaction_pool::BasicPool< sc_transaction_pool::FullChainApi, ConcreteBlock diff --git a/substrate/client/block-builder/src/lib.rs b/substrate/client/block-builder/src/lib.rs index 26bc9ecea8..9bc14cb6e9 100644 --- a/substrate/client/block-builder/src/lib.rs +++ b/substrate/client/block-builder/src/lib.rs @@ -121,7 +121,7 @@ where backend, }) } - + /// Push onto the block's list of extrinsics. /// /// This will ensure the extrinsic can be validly executed (by executing it). @@ -141,60 +141,36 @@ where let block_id = &self.block_id; let extrinsics = &mut self.extrinsics; - if self + let use_trusted = skip_signature && self .api .has_api_with::>, _>( block_id, - |version| version < 4, - )? - { - // Run compatibility fallback for v3. - self.api.map_api_result(|api| { - #[allow(deprecated)] - match api.apply_extrinsic_before_version_4_with_context( + |version| version >= 5, + )?; + + self.api.map_api_result(|api| { + let apply_result = if use_trusted { + api.apply_trusted_extrinsic_with_context( block_id, ExecutionContext::BlockConstruction, xt.clone(), - )? { - Ok(_) => { - extrinsics.push(xt); - Ok(()) - } - Err(e) => Err(ApplyExtrinsicFailed::from(e).into()), - } - }) - } else { - let use_trusted = skip_signature && self - .api - .has_api_with::>, _>( + )? + } else { + api.apply_extrinsic_with_context( block_id, - |version| version >= 5, - )?; + ExecutionContext::BlockConstruction, + xt.clone(), + )? + }; - self.api.map_api_result(|api| { - let apply_result = if use_trusted { - api.apply_trusted_extrinsic_with_context( - block_id, - ExecutionContext::BlockConstruction, - xt.clone(), - )? - } else { - api.apply_extrinsic_with_context( - block_id, - ExecutionContext::BlockConstruction, - xt.clone(), - )? - }; - - match apply_result { - Ok(_) => { - extrinsics.push(xt); - Ok(()) - } - Err(tx_validity) => Err(ApplyExtrinsicFailed::Validity(tx_validity).into()), + match apply_result { + Ok(_) => { + extrinsics.push(xt); + Ok(()) } - }) - } + Err(tx_validity) => Err(ApplyExtrinsicFailed::Validity(tx_validity).into()), + } + }) } /// Consume the builder to build a valid `Block` containing all pushed extrinsics. diff --git a/substrate/client/consensus/babe/src/lib.rs b/substrate/client/consensus/babe/src/lib.rs index b93619b29c..e04e112d7d 100644 --- a/substrate/client/consensus/babe/src/lib.rs +++ b/substrate/client/consensus/babe/src/lib.rs @@ -693,49 +693,6 @@ impl BabeVerifier { } } -#[allow(dead_code)] -fn median_algorithm( - median_required_blocks: u64, - slot_duration: u64, - slot_number: u64, - slot_now: u64, - time_source: &mut (Option, Vec<(Instant, u64)>), -) { - let num_timestamps = time_source.1.len(); - if num_timestamps as u64 >= median_required_blocks && median_required_blocks > 0 { - let mut new_list: Vec<_> = time_source.1.iter().map(|&(t, sl)| { - let offset: u128 = u128::from(slot_duration) - .checked_mul(1_000_000u128) // self.config.slot_duration returns milliseconds - .and_then(|x| { - x.checked_mul(u128::from(slot_number).saturating_sub(u128::from(sl))) - }) - .expect("we cannot have timespans long enough for this to overflow; qed"); - - const NANOS_PER_SEC: u32 = 1_000_000_000; - let nanos = (offset % u128::from(NANOS_PER_SEC)) as u32; - let secs = (offset / u128::from(NANOS_PER_SEC)) as u64; - - t + Duration::new(secs, nanos) - }).collect(); - - // Use a partial sort to move the median timestamp to the middle of the list - pdqselect::select(&mut new_list, num_timestamps / 2); - - let &median = new_list - .get(num_timestamps / 2) - .expect("we have at least one timestamp, so this is a valid index; qed"); - - let now = Instant::now(); - if now >= median { - time_source.0.replace(now - median); - } - - time_source.1.clear(); - } else { - time_source.1.push((Instant::now(), slot_now)) - } -} - impl Verifier for BabeVerifier where Block: BlockT, B: Backend + 'static, diff --git a/substrate/frame/babe/src/lib.rs b/substrate/frame/babe/src/lib.rs index aba3a75eb9..4dc9304fa8 100644 --- a/substrate/frame/babe/src/lib.rs +++ b/substrate/frame/babe/src/lib.rs @@ -248,7 +248,6 @@ impl pallet_session::ShouldEndSession for Module { /// A BABE equivocation offence report. /// /// When a validator released two or more blocks at the same slot. -#[allow(dead_code)] struct BabeEquivocationOffence { /// A babe slot number in which this incident happened. slot: u64, diff --git a/substrate/frame/babe/src/mock.rs b/substrate/frame/babe/src/mock.rs index efb5570c1d..aef0b4b386 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -15,17 +15,15 @@ // along with Substrate. If not, see . //! Test utilities -#![allow(dead_code, unused_imports)] use super::{Trait, Module, GenesisConfig}; -use sp_consensus_babe::AuthorityId; use sp_runtime::{ - traits::IdentityLookup, Perbill, PerThing, testing::{Header, UintAuthorityId}, impl_opaque_keys, + traits::IdentityLookup, Perbill, testing::{Header, UintAuthorityId}, impl_opaque_keys, }; use sp_version::RuntimeVersion; use frame_support::{impl_outer_origin, parameter_types, weights::Weight}; use sp_io; -use sp_core::{H256, Blake2Hasher}; +use sp_core::H256; impl_outer_origin!{ pub enum Origin for Test where system = frame_system {} diff --git a/substrate/frame/babe/src/tests.rs b/substrate/frame/babe/src/tests.rs index 976a264d7b..84f8166b10 100644 --- a/substrate/frame/babe/src/tests.rs +++ b/substrate/frame/babe/src/tests.rs @@ -17,7 +17,7 @@ //! Consensus extension module tests for BABE consensus. use super::*; -use mock::{new_test_ext, Babe, Test}; +use mock::{new_test_ext, Babe, System}; use sp_runtime::{traits::OnFinalize, testing::{Digest, DigestItem}}; use pallet_session::ShouldEndSession; @@ -66,8 +66,6 @@ fn check_module() { }) } -type System = frame_system::Module; - #[test] fn first_block_epoch_zero_start() { new_test_ext(vec![0, 1, 2, 3]).execute_with(|| { diff --git a/substrate/frame/grandpa/src/lib.rs b/substrate/frame/grandpa/src/lib.rs index 6d3223f094..3210627f91 100644 --- a/substrate/frame/grandpa/src/lib.rs +++ b/substrate/frame/grandpa/src/lib.rs @@ -481,7 +481,6 @@ struct GrandpaTimeSlot { // TODO [slashing]: Integrate this. /// A grandpa equivocation offence report. -#[allow(dead_code)] struct GrandpaEquivocationOffence { /// Time slot at which this incident happened. time_slot: GrandpaTimeSlot, diff --git a/substrate/primitives/block-builder/src/lib.rs b/substrate/primitives/block-builder/src/lib.rs index e4e98e1f40..71c2a3ccb5 100644 --- a/substrate/primitives/block-builder/src/lib.rs +++ b/substrate/primitives/block-builder/src/lib.rs @@ -22,37 +22,10 @@ use sp_runtime::{traits::Block as BlockT, ApplyExtrinsicResult}; use sp_inherents::{InherentData, CheckInherentsResult}; -/// Definitions for supporting the older version of API: v3 -/// -/// These definitions are taken from the 2c58e30246a029b53d51e5b24c31974ac539ee8b git revision. -#[deprecated(note = "These definitions here are only for compatibility reasons")] -pub mod compatibility_v3 { - use sp_runtime::{DispatchOutcome, transaction_validity}; - use codec::{Encode, Decode}; - - #[derive(Eq, PartialEq, Clone, Copy, Decode, Encode, Debug)] - pub enum ApplyError { - NoPermission, - BadState, - Validity(transaction_validity::TransactionValidityError), - } - - // `ApplyOutcome` was renamed to `DispatchOutcome` with the layout preserved. - pub type ApplyResult = Result; -} - sp_api::decl_runtime_apis! { /// The `BlockBuilder` api trait that provides the required functionality for building a block. #[api_version(5)] pub trait BlockBuilder { - /// Compatibility version of `apply_extrinsic` for v3. - /// - /// Only the return type is changed. - #[changed_in(4)] - #[allow(deprecated)] - fn apply_extrinsic(extrinsic: ::Extrinsic) - -> self::compatibility_v3::ApplyResult; - /// Apply the given extrinsic. /// /// Returns an inclusion outcome which specifies if this extrinsic is included in diff --git a/substrate/primitives/blockchain/src/error.rs b/substrate/primitives/blockchain/src/error.rs index ece20d1cf8..a4ec9c2995 100644 --- a/substrate/primitives/blockchain/src/error.rs +++ b/substrate/primitives/blockchain/src/error.rs @@ -19,8 +19,6 @@ use std::{self, error, result}; use sp_state_machine; use sp_runtime::transaction_validity::TransactionValidityError; -#[allow(deprecated)] -use sp_block_builder::compatibility_v3; use sp_consensus; use derive_more::{Display, From}; use codec::Error as CodecError; @@ -150,17 +148,6 @@ impl<'a> From<&'a str> for Error { } } -#[allow(deprecated)] -impl From for ApplyExtrinsicFailed { - fn from(e: compatibility_v3::ApplyError) -> Self { - use self::compatibility_v3::ApplyError::*; - match e { - Validity(tx_validity) => Self::Validity(tx_validity), - e => Self::Msg(format!("Apply extrinsic failed: {:?}", e)), - } - } -} - impl Error { /// Chain a blockchain error. pub fn from_blockchain(e: Box) -> Self {