mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 07:41:08 +00:00
remove aura inherent-checking compatibility shim (#2044)
This commit is contained in:
committed by
André Silva
parent
3501746fa9
commit
e83a39fee3
@@ -16,46 +16,10 @@
|
||||
|
||||
//! The runtime api for building blocks.
|
||||
|
||||
use runtime_primitives::{traits::Block as BlockT, ApplyResult, RuntimeString};
|
||||
use runtime_primitives::{traits::Block as BlockT, ApplyResult};
|
||||
use rstd::vec::Vec;
|
||||
use sr_api_macros::decl_runtime_apis;
|
||||
pub use inherents::{InherentData, CheckInherentsResult};
|
||||
use parity_codec::{Encode, Decode};
|
||||
|
||||
/// The old representation of the inherent data.
|
||||
#[doc(hide)]
|
||||
#[derive(Encode, Decode)]
|
||||
pub struct OldInherentData {
|
||||
/// Current timestamp.
|
||||
pub timestamp: u64,
|
||||
/// Blank report.
|
||||
pub consensus: (),
|
||||
/// Aura expected slot. Can take any value during block construction.
|
||||
pub aura_expected_slot: u64,
|
||||
}
|
||||
|
||||
impl OldInherentData {
|
||||
/// Create a new `BasicInherentData` instance.
|
||||
pub fn new(timestamp: u64, expected_slot: u64) -> Self {
|
||||
Self {
|
||||
timestamp,
|
||||
consensus: (),
|
||||
aura_expected_slot: expected_slot,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Error type used while checking inherents.
|
||||
#[doc(hide)]
|
||||
#[derive(Encode, PartialEq)]
|
||||
#[cfg_attr(feature = "std", derive(Decode))]
|
||||
pub enum OldCheckInherentError {
|
||||
/// The inherents are generally valid but a delay until the given timestamp
|
||||
/// is required.
|
||||
ValidAtTimestamp(u64),
|
||||
/// Some other error has occurred.
|
||||
Other(RuntimeString),
|
||||
}
|
||||
|
||||
decl_runtime_apis! {
|
||||
/// The `BlockBuilder` api trait that provides required functions for building a block for a runtime.
|
||||
@@ -69,11 +33,6 @@ decl_runtime_apis! {
|
||||
fn inherent_extrinsics(inherent: InherentData) -> Vec<<Block as BlockT>::Extrinsic>;
|
||||
/// Check that the inherents are valid. The inherent data will vary from chain to chain.
|
||||
fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult;
|
||||
/// Check that the inherents are valid. The inherent data will vary from chain to chain.
|
||||
///
|
||||
/// Old version that is used by the CC network.
|
||||
#[changed_in(2)]
|
||||
fn check_inherents(block: Block, data: OldInherentData) -> ::std::result::Result<(), OldCheckInherentError>;
|
||||
/// Generate a random seed.
|
||||
fn random_seed() -> <Block as BlockT>::Hash;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ use consensus_common::{
|
||||
};
|
||||
use consensus_common::import_queue::{Verifier, BasicQueue, SharedBlockImport, SharedJustificationImport};
|
||||
use client::ChainHead;
|
||||
use client::block_builder::api::{BlockBuilder as BlockBuilderApi, self as block_builder_api};
|
||||
use client::block_builder::api::BlockBuilder as BlockBuilderApi;
|
||||
use client::runtime_api::ApiExt;
|
||||
use consensus_common::{ImportBlock, BlockOrigin};
|
||||
use runtime_primitives::{generic, generic::BlockId, Justification};
|
||||
@@ -497,51 +497,6 @@ impl<C, E> AuraVerifier<C, E>
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
fn old_check_inherents<B: Block>(
|
||||
&self,
|
||||
block: B,
|
||||
block_id: BlockId<B>,
|
||||
inherent_data: InherentData,
|
||||
timestamp_now: u64,
|
||||
) -> Result<(), String>
|
||||
where C: ProvideRuntimeApi, C::Api: BlockBuilderApi<B>
|
||||
{
|
||||
use block_builder_api::{OldInherentData, OldCheckInherentError};
|
||||
const MAX_TIMESTAMP_DRIFT_SECS: u64 = 60;
|
||||
|
||||
let (timestamp, slot) = AuraSlotCompatible::extract_timestamp_and_slot(&inherent_data).map_err(|e| format!("{:?}", e))?;
|
||||
let inherent_data = OldInherentData::new(timestamp, slot);
|
||||
|
||||
let inherent_res = self.client.runtime_api().check_inherents_before_version_2(
|
||||
&block_id,
|
||||
block,
|
||||
inherent_data,
|
||||
).map_err(|e| format!("{:?}", e))?;
|
||||
|
||||
match inherent_res {
|
||||
Ok(()) => Ok(()),
|
||||
Err(OldCheckInherentError::ValidAtTimestamp(timestamp)) => {
|
||||
// halt import until timestamp is valid.
|
||||
// reject when too far ahead.
|
||||
if timestamp > timestamp_now + MAX_TIMESTAMP_DRIFT_SECS {
|
||||
return Err("Rejecting block too far in future".into());
|
||||
}
|
||||
|
||||
let diff = timestamp.saturating_sub(timestamp_now);
|
||||
info!(
|
||||
target: "aura",
|
||||
"halting for block {} seconds in the future",
|
||||
diff
|
||||
);
|
||||
telemetry!(CONSENSUS_INFO; "aura.halting_for_future_block"; "diff" => ?diff);
|
||||
thread::sleep(Duration::from_secs(diff));
|
||||
Ok(())
|
||||
},
|
||||
Err(OldCheckInherentError::Other(e)) => Err(e.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// No-op extra verification.
|
||||
@@ -596,18 +551,12 @@ impl<B: Block, C, E> Verifier<B> for AuraVerifier<C, E> where
|
||||
inherent_data.aura_replace_inherent_data(slot_num);
|
||||
let block = B::new(pre_header.clone(), inner_body);
|
||||
|
||||
// skip the inherents verification if the runtime API is old.
|
||||
if self.client
|
||||
.runtime_api()
|
||||
.has_api_with::<BlockBuilderApi<B>, _>(&BlockId::Hash(parent_hash), |v| v < 2)
|
||||
.has_api_with::<BlockBuilderApi<B>, _>(&BlockId::Hash(parent_hash), |v| v >= 2)
|
||||
.map_err(|e| format!("{:?}", e))?
|
||||
{
|
||||
self.old_check_inherents(
|
||||
block.clone(),
|
||||
BlockId::Hash(parent_hash),
|
||||
inherent_data,
|
||||
timestamp_now,
|
||||
)?;
|
||||
} else {
|
||||
self.check_inherents(
|
||||
block.clone(),
|
||||
BlockId::Hash(parent_hash),
|
||||
|
||||
Reference in New Issue
Block a user