Skip to content
Snippets Groups Projects
Commit 90de5591 authored by Peter Goodspeed-Niklaus's avatar Peter Goodspeed-Niklaus Committed by GitHub
Browse files

impl ProvideInherent for InclusionInherent (#1318)

* impl ProvideInherent for InclusionInherent

* reduce import churn; correct expect message

* move inclusion inherent identifier into primitives

It's not clear precisely why this is desired, but it's a pattern
I've seen in several places, so I'm going this to be on the
safe side. Worst case, we can revert this commit pretty easily.

* bump kusama spec_version to placate CI

* add license header

* empty commit; maybe github will notice the one with changes

* add sanity check to only include valid inherents
parent b26f6d08
No related merge requests found
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! Inclusion Inherent primitives define types and constants which can be imported
//! without needing to import the entire inherent module.
use inherents::InherentIdentifier;
/// Unique identifier for the Inclusion Inherent
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"inclusn0";
......@@ -23,6 +23,7 @@
use runtime_primitives::{generic, MultiSignature};
pub use runtime_primitives::traits::{BlakeTwo256, Hash as HashT, Verify, IdentifyAccount};
pub mod inclusion_inherent;
pub mod parachain;
pub use parity_scale_codec::Compact;
......
......@@ -722,6 +722,12 @@ pub type SignedAvailabilityBitfield = Signed<AvailabilityBitfield>;
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)]
pub struct SignedAvailabilityBitfields(pub Vec<SignedAvailabilityBitfield>);
impl From<Vec<SignedAvailabilityBitfield>> for SignedAvailabilityBitfields {
fn from(fields: Vec<SignedAvailabilityBitfield>) -> SignedAvailabilityBitfields {
SignedAvailabilityBitfields(fields)
}
}
/// A backed (or backable, depending on context) candidate.
// TODO: yes, this is roughly the same as AttestedCandidate.
// After https://github.com/paritytech/polkadot/issues/1250
......
......@@ -23,18 +23,23 @@
use sp_std::prelude::*;
use primitives::{
inclusion_inherent,
parachain::{BackedCandidate, SignedAvailabilityBitfields},
};
use frame_support::{
decl_storage, decl_module, decl_error, ensure,
decl_error, decl_module, decl_storage, ensure,
dispatch::DispatchResult,
weights::{DispatchClass, Weight},
traits::Get,
};
use system::ensure_none;
use crate::{inclusion, scheduler::{self, FreedReason}};
use crate::{
inclusion,
scheduler::{self, FreedReason},
};
use inherents::{InherentIdentifier, InherentData, MakeFatalError, ProvideInherent};
pub trait Trait: inclusion::Trait + scheduler::Trait { }
pub trait Trait: inclusion::Trait + scheduler::Trait {}
decl_storage! {
trait Store for Module<T: Trait> as ParaInclusionInherent {
......@@ -118,3 +123,23 @@ decl_module! {
}
}
}
impl<T: Trait> ProvideInherent for Module<T> {
type Call = Call<T>;
type Error = MakeFatalError<()>;
const INHERENT_IDENTIFIER: InherentIdentifier = inclusion_inherent::INHERENT_IDENTIFIER;
fn create_inherent(data: &InherentData) -> Option<Self::Call> {
data.get_data(&Self::INHERENT_IDENTIFIER)
.expect("inclusion inherent data failed to decode")
.map(|(signed_bitfields, backed_candidates): (SignedAvailabilityBitfields, Vec<BackedCandidate<T::Hash>>)| {
// Sanity check: session changes can invalidate an inherent, and we _really_ don't want that to happen.
// See github.com/paritytech/polkadot/issues/1327
if Self::inclusion(system::RawOrigin::None.into(), signed_bitfields.clone(), backed_candidates.clone()).is_ok() {
Call::inclusion(signed_bitfields, backed_candidates)
} else {
Call::inclusion(Vec::new().into(), Vec::new())
}
})
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment