mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 23:37:56 +00:00
Updates substrate to latest master (#107)
* Updates substrate to latest master * Use slot_duration and not slot * Update to latest substrate master again to have latest CLI * Rename iherent indentifier * Update after master merge
This commit is contained in:
+12
-58
@@ -36,10 +36,10 @@ extern crate parity_codec as codec;
|
||||
|
||||
extern crate substrate_consensus_aura_primitives as consensus_aura;
|
||||
extern crate substrate_primitives;
|
||||
extern crate substrate_inherents as inherents;
|
||||
#[macro_use]
|
||||
extern crate substrate_client as client;
|
||||
|
||||
#[macro_use]
|
||||
extern crate sr_std as rstd;
|
||||
#[cfg(test)]
|
||||
extern crate sr_io;
|
||||
@@ -80,12 +80,11 @@ use primitives::{
|
||||
parachain,
|
||||
};
|
||||
use client::{
|
||||
block_builder::api as block_builder_api,
|
||||
block_builder::api::{self as block_builder_api, InherentData, CheckInherentsResult},
|
||||
runtime_api as client_api,
|
||||
};
|
||||
use consensus_aura::api as aura_api;
|
||||
use sr_primitives::{
|
||||
ApplyResult, CheckInherentError, generic, transaction_validity::TransactionValidity,
|
||||
ApplyResult, generic, transaction_validity::TransactionValidity,
|
||||
traits::{Convert, BlakeTwo256, Block as BlockT, DigestFor, StaticLookup}
|
||||
};
|
||||
use version::RuntimeVersion;
|
||||
@@ -102,15 +101,11 @@ pub use sr_primitives::BuildStorage;
|
||||
pub use consensus::Call as ConsensusCall;
|
||||
pub use timestamp::Call as TimestampCall;
|
||||
pub use balances::Call as BalancesCall;
|
||||
pub use parachains::Call as ParachainsCall;
|
||||
pub use parachains::{Call as ParachainsCall, INHERENT_IDENTIFIER as PARACHAIN_INHERENT_IDENTIFIER};
|
||||
pub use sr_primitives::{Permill, Perbill};
|
||||
pub use timestamp::BlockPeriod;
|
||||
pub use srml_support::{StorageValue, RuntimeMetadata};
|
||||
|
||||
const TIMESTAMP_SET_POSITION: u32 = 0;
|
||||
const PARACHAINS_SET_POSITION: u32 = 1;
|
||||
const NOTE_OFFLINE_POSITION: u32 = 2; // this should be reintroduced
|
||||
|
||||
/// Runtime version.
|
||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("polkadot"),
|
||||
@@ -164,7 +159,6 @@ impl balances::Trait for Runtime {
|
||||
}
|
||||
|
||||
impl consensus::Trait for Runtime {
|
||||
const NOTE_OFFLINE_POSITION: u32 = NOTE_OFFLINE_POSITION;
|
||||
type Log = Log;
|
||||
type SessionKey = SessionKey;
|
||||
|
||||
@@ -174,7 +168,6 @@ impl consensus::Trait for Runtime {
|
||||
}
|
||||
|
||||
impl timestamp::Trait for Runtime {
|
||||
const TIMESTAMP_SET_POSITION: u32 = TIMESTAMP_SET_POSITION;
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = Aura;
|
||||
}
|
||||
@@ -229,9 +222,7 @@ impl grandpa::Trait for Runtime {
|
||||
type Event = Event;
|
||||
}
|
||||
|
||||
impl parachains::Trait for Runtime {
|
||||
const SET_POSITION: u32 = PARACHAINS_SET_POSITION;
|
||||
}
|
||||
impl parachains::Trait for Runtime {}
|
||||
|
||||
impl upgrade_key::Trait for Runtime {
|
||||
type Event = Event;
|
||||
@@ -250,7 +241,7 @@ construct_runtime!(
|
||||
pub enum Runtime with Log(InternalLog: DigestItem<Hash, SessionKey>) where
|
||||
Block = Block,
|
||||
NodeBlock = primitives::Block,
|
||||
InherentData = primitives::InherentData
|
||||
UncheckedExtrinsic = UncheckedExtrinsic
|
||||
{
|
||||
System: system::{default, Log(ChangesTrieRoot)},
|
||||
Aura: aura::{Module},
|
||||
@@ -317,7 +308,7 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl block_builder_api::BlockBuilder<Block, primitives::InherentData> for Runtime {
|
||||
impl block_builder_api::BlockBuilder<Block> for Runtime {
|
||||
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyResult {
|
||||
Executive::apply_extrinsic(extrinsic)
|
||||
}
|
||||
@@ -326,48 +317,12 @@ impl_runtime_apis! {
|
||||
Executive::finalise_block()
|
||||
}
|
||||
|
||||
fn inherent_extrinsics(data: primitives::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
|
||||
use sr_primitives::traits::ProvideInherent;
|
||||
|
||||
let mut inherent = Vec::new();
|
||||
|
||||
inherent.extend(
|
||||
Timestamp::create_inherent_extrinsics(data.timestamp)
|
||||
.into_iter()
|
||||
.map(|v| (v.0, UncheckedExtrinsic::new_unsigned(Call::Timestamp(v.1))))
|
||||
);
|
||||
|
||||
inherent.extend(
|
||||
Parachains::create_inherent_extrinsics(data.parachains)
|
||||
.into_iter()
|
||||
.map(|v| (v.0, UncheckedExtrinsic::new_unsigned(Call::Parachains(v.1))))
|
||||
);
|
||||
|
||||
inherent.as_mut_slice().sort_unstable_by_key(|v| v.0);
|
||||
inherent.into_iter().map(|v| v.1).collect()
|
||||
fn inherent_extrinsics(data: InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
|
||||
data.create_extrinsics()
|
||||
}
|
||||
|
||||
fn check_inherents(block: Block, data: primitives::InherentData) -> Result<(), CheckInherentError> {
|
||||
let expected_slot = data.aura_expected_slot;
|
||||
|
||||
// draw timestamp out from extrinsics.
|
||||
let set_timestamp = block.extrinsics()
|
||||
.get(TIMESTAMP_SET_POSITION as usize)
|
||||
.and_then(|xt: &UncheckedExtrinsic| match xt.function {
|
||||
Call::Timestamp(TimestampCall::set(ref t)) => Some(t.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.ok_or_else(|| CheckInherentError::Other("No valid timestamp in block.".into()))?;
|
||||
|
||||
// take the "worse" result of normal verification and the timestamp vs. seal
|
||||
// check.
|
||||
CheckInherentError::combine_results(
|
||||
Runtime::check_inherents(block, data),
|
||||
|| {
|
||||
Aura::verify_inherent(set_timestamp.into(), expected_slot)
|
||||
.map_err(|s| CheckInherentError::Other(s.into()))
|
||||
},
|
||||
)
|
||||
fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult {
|
||||
data.check_extrinsics(&block)
|
||||
}
|
||||
|
||||
fn random_seed() -> <Block as BlockT>::Hash {
|
||||
@@ -419,10 +374,9 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl aura_api::AuraApi<Block> for Runtime {
|
||||
impl consensus_aura::AuraApi<Block> for Runtime {
|
||||
fn slot_duration() -> u64 {
|
||||
Aura::slot_duration()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,16 +20,15 @@ use rstd::prelude::*;
|
||||
use codec::Decode;
|
||||
|
||||
use bitvec::BigEndian;
|
||||
use sr_primitives::CheckInherentError;
|
||||
use sr_primitives::traits::{
|
||||
Extrinsic, Block as BlockT, Hash as HashT, BlakeTwo256, ProvideInherent,
|
||||
};
|
||||
use sr_primitives::traits::{Hash as HashT, BlakeTwo256};
|
||||
use primitives::parachain::{Id as ParaId, Chain, DutyRoster, AttestedCandidate, Statement};
|
||||
use {system, session};
|
||||
|
||||
use srml_support::{StorageValue, StorageMap};
|
||||
use srml_support::dispatch::Result;
|
||||
|
||||
use inherents::{ProvideInherent, InherentData, RuntimeString, MakeFatalError, InherentIdentifier};
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use sr_primitives::{self, ChildrenStorageMap};
|
||||
|
||||
@@ -38,10 +37,7 @@ use rstd::marker::PhantomData;
|
||||
|
||||
use system::ensure_inherent;
|
||||
|
||||
pub trait Trait: session::Trait {
|
||||
/// The position of the set_heads call in the block.
|
||||
const SET_POSITION: u32;
|
||||
}
|
||||
pub trait Trait: session::Trait {}
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as Parachains {
|
||||
@@ -87,11 +83,6 @@ decl_module! {
|
||||
fn set_heads(origin, heads: Vec<AttestedCandidate>) -> Result {
|
||||
ensure_inherent(origin)?;
|
||||
ensure!(!<DidUpdate<T>>::exists(), "Parachain heads must be updated only once in the block");
|
||||
ensure!(
|
||||
<system::Module<T>>::extrinsic_index() == Some(T::SET_POSITION),
|
||||
"Parachain heads update extrinsic must be at position {} in the block"
|
||||
// , T::SET_POSITION
|
||||
);
|
||||
|
||||
let active_parachains = Self::active_parachains();
|
||||
|
||||
@@ -378,34 +369,21 @@ impl<T: Trait> Module<T> {
|
||||
*/
|
||||
}
|
||||
|
||||
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"newheads";
|
||||
|
||||
pub type InherentType = Vec<AttestedCandidate>;
|
||||
|
||||
impl<T: Trait> ProvideInherent for Module<T> {
|
||||
type Inherent = Vec<AttestedCandidate>;
|
||||
type Call = Call<T>;
|
||||
type Error = MakeFatalError<RuntimeString>;
|
||||
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
|
||||
|
||||
fn create_inherent_extrinsics(data: Self::Inherent) -> Vec<(u32, Self::Call)> {
|
||||
vec![(T::SET_POSITION, Call::set_heads(data))]
|
||||
}
|
||||
fn create_inherent(data: &InherentData) -> Option<Self::Call> {
|
||||
let data = data.get_data::<InherentType>(&INHERENT_IDENTIFIER)
|
||||
.expect("Parachain heads could not be decoded.")
|
||||
.expect("No parachain heads found in inherent data.");
|
||||
|
||||
fn check_inherent<Block: BlockT, F: Fn(&Block::Extrinsic) -> Option<&Self::Call>>(
|
||||
block: &Block, _data: Self::Inherent, extract_function: &F
|
||||
) -> ::rstd::result::Result<(), CheckInherentError> {
|
||||
let has_heads = block
|
||||
.extrinsics()
|
||||
.get(T::SET_POSITION as usize)
|
||||
.map_or(false, |xt| {
|
||||
xt.is_signed() == Some(false) && match extract_function(&xt) {
|
||||
Some(Call::set_heads(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
});
|
||||
|
||||
if !has_heads {
|
||||
return Err(CheckInherentError::Other(
|
||||
"No valid parachains inherent in block".into()
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Some(Call::set_heads(data))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,7 +405,6 @@ mod tests {
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct Test;
|
||||
impl consensus::Trait for Test {
|
||||
const NOTE_OFFLINE_POSITION: u32 = 1;
|
||||
type SessionKey = SessionKey;
|
||||
type InherentOfflineReport = ();
|
||||
type Log = ::Log;
|
||||
@@ -451,13 +428,10 @@ mod tests {
|
||||
type Event = ();
|
||||
}
|
||||
impl timestamp::Trait for Test {
|
||||
const TIMESTAMP_SET_POSITION: u32 = 0;
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = ();
|
||||
}
|
||||
impl Trait for Test {
|
||||
const SET_POSITION: u32 = 0;
|
||||
}
|
||||
impl Trait for Test {}
|
||||
|
||||
type Parachains = Module<Test>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user