mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 04:31:08 +00:00
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 <shawntabrizi@gmail.com>
This commit is contained in:
@@ -264,9 +264,7 @@ macro_rules! new_full {
|
||||
}}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
type ConcreteBlock = node_primitives::Block;
|
||||
#[allow(dead_code)]
|
||||
type ConcreteClient =
|
||||
Client<
|
||||
Backend<ConcreteBlock>,
|
||||
@@ -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
|
||||
|
||||
@@ -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::<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,
|
||||
)?;
|
||||
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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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>;
|
||||
|
||||
#[test]
|
||||
fn first_block_epoch_zero_start() {
|
||||
new_test_ext(vec![0, 1, 2, 3]).execute_with(|| {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<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 {
|
||||
|
||||
Reference in New Issue
Block a user