Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Remove deprecated API (#4993)
Browse files Browse the repository at this point in the history
* Remove deprecated API

* Remove (some) allow(dead_code)

* Bump spec_version

* Fix import, remove allow dead code.

Co-authored-by: Shawn Tabrizi <[email protected]>
  • Loading branch information
stanislav-tkach and shawntabrizi authored Feb 20, 2020
1 parent 99cc19d commit dbeebe2
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 143 deletions.
4 changes: 0 additions & 4 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ macro_rules! new_full {
}}
}

#[allow(dead_code)]
type ConcreteBlock = node_primitives::Block;
#[allow(dead_code)]
type ConcreteClient =
Client<
Backend<ConcreteBlock>,
Expand All @@ -275,9 +273,7 @@ type ConcreteClient =
ConcreteBlock,
node_runtime::RuntimeApi
>;
#[allow(dead_code)]
type ConcreteBackend = Backend<ConcreteBlock>;
#[allow(dead_code)]
type ConcreteTransactionPool = sc_transaction_pool::BasicPool<
sc_transaction_pool::FullChainApi<ConcreteClient, ConcreteBlock>,
ConcreteBlock
Expand Down
70 changes: 23 additions & 47 deletions client/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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::<dyn BlockBuilderApi<Block, Error = ApiErrorFor<A, Block>>, _>(
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::<dyn BlockBuilderApi<Block, Error = ApiErrorFor<A, Block>>, _>(
)?
} else {
api.apply_extrinsic_with_context(
block_id,
|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(),
)?
} 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()),
ExecutionContext::BlockConstruction,
xt.clone(),
)?
};

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.
Expand Down
43 changes: 0 additions & 43 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,49 +693,6 @@ impl<B, E, Block: BlockT, RA, PRA> BabeVerifier<B, E, Block, RA, PRA> {
}
}

#[allow(dead_code)]
fn median_algorithm(
median_required_blocks: u64,
slot_duration: u64,
slot_number: u64,
slot_now: u64,
time_source: &mut (Option<Duration>, 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<B, E, Block, RA, PRA> Verifier<Block> for BabeVerifier<B, E, Block, RA, PRA> where
Block: BlockT,
B: Backend<Block> + 'static,
Expand Down
1 change: 0 additions & 1 deletion frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ impl<T: Trait> pallet_session::ShouldEndSession<T::BlockNumber> for Module<T> {
/// A BABE equivocation offence report.
///
/// When a validator released two or more blocks at the same slot.
#[allow(dead_code)]
struct BabeEquivocationOffence<FullIdentification> {
/// A babe slot number in which this incident happened.
slot: u64,
Expand Down
6 changes: 2 additions & 4 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! 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 {}
Expand Down
4 changes: 1 addition & 3 deletions frame/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -66,8 +66,6 @@ fn check_module() {
})
}

type System = frame_system::Module<Test>;

#[test]
fn first_block_epoch_zero_start() {
new_test_ext(vec![0, 1, 2, 3]).execute_with(|| {
Expand Down
1 change: 0 additions & 1 deletion frame/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ struct GrandpaTimeSlot {

// TODO [slashing]: Integrate this.
/// A grandpa equivocation offence report.
#[allow(dead_code)]
struct GrandpaEquivocationOffence<FullIdentification> {
/// Time slot at which this incident happened.
time_slot: GrandpaTimeSlot,
Expand Down
27 changes: 0 additions & 27 deletions primitives/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DispatchOutcome, ApplyError>;
}

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: <Block as BlockT>::Extrinsic)
-> self::compatibility_v3::ApplyResult;

/// Apply the given extrinsic.
///
/// Returns an inclusion outcome which specifies if this extrinsic is included in
Expand Down
13 changes: 0 additions & 13 deletions primitives/blockchain/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -150,17 +148,6 @@ impl<'a> From<&'a str> for Error {
}
}

#[allow(deprecated)]
impl From<compatibility_v3::ApplyError> 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<Error>) -> Self {
Expand Down

0 comments on commit dbeebe2

Please sign in to comment.