mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 15:11:02 +00:00
Update to latest Substrate master. (#353)
* Integrate srml/im-online * Fix all build errors with old aura. * Fix most of the build errors. * Builds and tests seem to pass (I will not trust this commit yet) * Apply suggestions from code review Co-Authored-By: Robert Habermeier <rphmeier@gmail.com> * Kill some warnings. * fix panics on 0 validators * Fix dev chain. * Fix author stuff * fix im online integration. * Some tweaks * Introduce app-crypto * Initial build work * codec update / tweaks * patch polkadot-erasure-coding input * More fixes for new crypto * More fixes * Update parachains module * evamp parachain crypto * More crypto work. * Chain spec and service. * ChainSpec stuff * Last bits for a clean build * Tweak coment * adapt polkadot-validation to the new keystore * polkadot-network compiles, but tests don't * Integrate the new parachain validation stuff * delete message_routing file * make polkadot-network tests compile and pass * runtime tests compile and pass * update substrate ref * service compiles * all tests pass * Add TODO, change branch back to polkadot-master * Lock file * TODOs done * Issue number * Remove old tODO * Remove commented code
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
//! as well.
|
||||
|
||||
use rstd::prelude::*;
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
use srml_support::{decl_storage, decl_module, ensure};
|
||||
|
||||
use primitives::{Hash, parachain::{AttestedCandidate, CandidateReceipt, Id as ParaId}};
|
||||
|
||||
@@ -21,7 +21,7 @@ use sr_io::{keccak_256, secp256k1_ecdsa_recover};
|
||||
use srml_support::{StorageValue, StorageMap, decl_event, decl_storage, decl_module};
|
||||
use srml_support::traits::{Currency, Get};
|
||||
use system::ensure_none;
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
#[cfg(feature = "std")]
|
||||
use sr_primitives::traits::Zero;
|
||||
use sr_primitives::{
|
||||
@@ -200,7 +200,7 @@ mod tests {
|
||||
|
||||
use sr_io::with_externalities;
|
||||
use substrate_primitives::{H256, Blake2Hasher};
|
||||
use parity_codec::{Decode, Encode};
|
||||
use codec::{Decode, Encode};
|
||||
// The testing primitives are very useful for avoiding having to work with signatures
|
||||
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
|
||||
use sr_primitives::{Perbill, traits::{BlakeTwo256, IdentityLookup, ConvertInto}, testing::Header};
|
||||
@@ -210,20 +210,20 @@ mod tests {
|
||||
impl_outer_origin! {
|
||||
pub enum Origin for Test {}
|
||||
}
|
||||
|
||||
// For testing the module, we construct most of a mock runtime. This means
|
||||
// first constructing a configuration type (`Test`) which `impl`s each of the
|
||||
// configuration traits of modules we want to use.
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct Test;
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub const BlockHashCount: u32 = 250;
|
||||
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
|
||||
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
|
||||
}
|
||||
impl system::Trait for Test {
|
||||
type Origin = Origin;
|
||||
type Call = ();
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -305,12 +305,12 @@ mod tests {
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
// our desired mockup.
|
||||
fn new_test_ext() -> sr_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap().0;
|
||||
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
// We use default for brevity, but you can configure as desired if needed.
|
||||
t.extend(balances::GenesisConfig::<Test>::default().build_storage().unwrap().0);
|
||||
t.extend(GenesisConfig::<Test>{
|
||||
balances::GenesisConfig::<Test>::default().assimilate_storage(&mut t).unwrap();
|
||||
GenesisConfig::<Test>{
|
||||
claims: vec![(alice_eth(), 100)],
|
||||
}.build_storage().unwrap().0);
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
t.into()
|
||||
}
|
||||
|
||||
|
||||
@@ -19,17 +19,31 @@ pub mod currency {
|
||||
use primitives::Balance;
|
||||
|
||||
pub const DOTS: Balance = 1_000_000_000_000;
|
||||
pub const BUCKS: Balance = DOTS / 100;
|
||||
pub const CENTS: Balance = BUCKS / 100;
|
||||
pub const DOLLARS: Balance = DOTS / 100;
|
||||
pub const CENTS: Balance = DOLLARS / 100;
|
||||
pub const MILLICENTS: Balance = CENTS / 1_000;
|
||||
}
|
||||
|
||||
|
||||
/// Time.
|
||||
pub mod time {
|
||||
pub const SECS_PER_BLOCK: u64 = 6;
|
||||
pub const MINUTES: u64 = 60 / SECS_PER_BLOCK;
|
||||
pub const HOURS: u64 = MINUTES * 60;
|
||||
pub const DAYS: u64 = HOURS * 24;
|
||||
use primitives::{Moment, BlockNumber};
|
||||
pub const MILLISECS_PER_BLOCK: Moment = 6000;
|
||||
pub const SECS_PER_BLOCK: Moment = MILLISECS_PER_BLOCK / 1000;
|
||||
|
||||
pub const SLOT_DURATION: Moment = 1650;
|
||||
|
||||
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 10 * MINUTES;
|
||||
pub const EPOCH_DURATION_IN_SLOTS: u64 = {
|
||||
const SLOT_FILL_RATE: f64 = MILLISECS_PER_BLOCK as f64 / SLOT_DURATION as f64;
|
||||
|
||||
(EPOCH_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as u64
|
||||
};
|
||||
|
||||
// These time units are defined in number of blocks.
|
||||
pub const MINUTES: BlockNumber = 60 / (SECS_PER_BLOCK as BlockNumber);
|
||||
pub const HOURS: BlockNumber = MINUTES * 60;
|
||||
pub const DAYS: BlockNumber = HOURS * 24;
|
||||
}
|
||||
|
||||
/// Fee-related.
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! A module for manually curated GRANDPA set.
|
||||
|
||||
use {grandpa, system};
|
||||
use parity_codec::Decode;
|
||||
use codec::Decode;
|
||||
use sr_primitives::traits::{Hash as HashT, BlakeTwo256, Zero};
|
||||
use sr_primitives::weights::SimpleDispatchInfo;
|
||||
use rstd::prelude::*;
|
||||
@@ -79,7 +79,7 @@ decl_module! {
|
||||
let offset = (i * 4 % 32) as usize;
|
||||
|
||||
// number of roles remaining to select from.
|
||||
let remaining = (voter_count - i) as usize;
|
||||
let remaining = rstd::cmp::max(1, (voter_count - i) as usize);
|
||||
|
||||
// 8 32-bit ints per 256-bit seed.
|
||||
let voter_index = u32::decode(&mut &seed[offset..offset + 4]).expect("using 4 bytes for a 32-bit quantity") as usize % remaining;
|
||||
|
||||
+109
-44
@@ -30,8 +30,8 @@ mod slots;
|
||||
use rstd::prelude::*;
|
||||
use substrate_primitives::u32_trait::{_1, _2, _3, _4};
|
||||
use primitives::{
|
||||
AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, SessionKey, Signature,
|
||||
parachain, AuraId
|
||||
AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment,
|
||||
parachain,
|
||||
};
|
||||
use client::{
|
||||
block_builder::api::{self as block_builder_api, InherentData, CheckInherentsResult},
|
||||
@@ -44,6 +44,7 @@ use sr_primitives::{
|
||||
};
|
||||
use version::RuntimeVersion;
|
||||
use grandpa::{AuthorityId as GrandpaId, fg_primitives::{self, ScheduledChange}};
|
||||
use babe_primitives::AuthorityId as BabeId;
|
||||
use elections::VoteIndex;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use version::NativeVersion;
|
||||
@@ -51,6 +52,7 @@ use substrate_primitives::OpaqueMetadata;
|
||||
use srml_support::{
|
||||
parameter_types, construct_runtime, traits::{SplitTwoWays, Currency}
|
||||
};
|
||||
use im_online::AuthorityId as ImOnlineId;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use staking::StakerStatus;
|
||||
@@ -97,7 +99,7 @@ pub fn native_version() -> NativeVersion {
|
||||
type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
|
||||
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub const BlockHashCount: BlockNumber = 250;
|
||||
pub const MaximumBlockWeight: Weight = 1_000_000_000;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
|
||||
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
|
||||
@@ -105,6 +107,7 @@ parameter_types! {
|
||||
|
||||
impl system::Trait for Runtime {
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
type Index = Nonce;
|
||||
type BlockNumber = BlockNumber;
|
||||
type Hash = Hash;
|
||||
@@ -120,9 +123,14 @@ impl system::Trait for Runtime {
|
||||
type AvailableBlockRatio = AvailableBlockRatio;
|
||||
}
|
||||
|
||||
impl aura::Trait for Runtime {
|
||||
type HandleReport = aura::StakingSlasher<Runtime>;
|
||||
type AuthorityId = AuraId;
|
||||
parameter_types! {
|
||||
pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS;
|
||||
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
|
||||
}
|
||||
|
||||
impl babe::Trait for Runtime {
|
||||
type EpochDuration = EpochDuration;
|
||||
type ExpectedBlockTime = ExpectedBlockTime;
|
||||
}
|
||||
|
||||
impl indices::Trait for Runtime {
|
||||
@@ -144,8 +152,8 @@ parameter_types! {
|
||||
pub type DealWithFees = SplitTwoWays<
|
||||
Balance,
|
||||
NegativeImbalance,
|
||||
_4, Treasury, // 4 parts (80%) goes to the treasury.
|
||||
_1, ToAuthor, // 1 part (20%) goes to the block author.
|
||||
_4, Treasury, // 4 parts (80%) goes to the treasury.
|
||||
_1, ToAuthor, // 1 part (20%) goes to the block author.
|
||||
>;
|
||||
|
||||
impl balances::Trait for Runtime {
|
||||
@@ -165,22 +173,22 @@ impl balances::Trait for Runtime {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MinimumPeriod: u64 = SECS_PER_BLOCK / 2;
|
||||
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
|
||||
}
|
||||
|
||||
impl timestamp::Trait for Runtime {
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = Aura;
|
||||
type OnTimestampSet = Babe;
|
||||
type MinimumPeriod = MinimumPeriod;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const UncleGenerations: u64 = 0;
|
||||
pub const UncleGenerations: u32 = 0;
|
||||
}
|
||||
|
||||
// TODO: substrate#2986 implement this properly
|
||||
impl authorship::Trait for Runtime {
|
||||
type FindAuthor = ();
|
||||
type FindAuthor = session::FindAccountFromAuthorIndex<Self, Babe>;
|
||||
type UncleGenerations = UncleGenerations;
|
||||
type FilterUncle = ();
|
||||
type EventHandler = ();
|
||||
@@ -191,11 +199,17 @@ parameter_types! {
|
||||
pub const Offset: BlockNumber = 0;
|
||||
}
|
||||
|
||||
type SessionHandlers = (Grandpa, Aura);
|
||||
type SessionHandlers = (Grandpa, Babe, ImOnline, Parachains);
|
||||
impl_opaque_keys! {
|
||||
pub struct SessionKeys {
|
||||
#[id(key_types::ED25519)]
|
||||
pub ed25519: GrandpaId,
|
||||
#[id(key_types::GRANDPA)]
|
||||
pub grandpa: GrandpaId,
|
||||
#[id(key_types::BABE)]
|
||||
pub babe: BabeId,
|
||||
#[id(key_types::IM_ONLINE)]
|
||||
pub im_online: ImOnlineId,
|
||||
#[id(parachain::PARACHAIN_KEY_TYPE_ID)]
|
||||
pub parachain_validator: parachain::ValidatorId,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +222,7 @@ impl_opaque_keys! {
|
||||
impl session::Trait for Runtime {
|
||||
type OnSessionEnding = Staking;
|
||||
type SessionHandler = SessionHandlers;
|
||||
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
|
||||
type ShouldEndSession = Babe;
|
||||
type Event = Event;
|
||||
type Keys = SessionKeys;
|
||||
type SelectInitialValidators = Staking;
|
||||
@@ -243,11 +257,9 @@ parameter_types! {
|
||||
pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
|
||||
pub const VotingPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
|
||||
pub const EmergencyVotingPeriod: BlockNumber = 3 * 24 * 60 * MINUTES;
|
||||
pub const MinimumDeposit: Balance = 100 * BUCKS;
|
||||
pub const MinimumDeposit: Balance = 100 * DOLLARS;
|
||||
pub const EnactmentPeriod: BlockNumber = 30 * 24 * 60 * MINUTES;
|
||||
pub const CooloffPeriod: BlockNumber = 30 * 24 * 60 * MINUTES;
|
||||
|
||||
pub const AttestationPeriod: BlockNumber = 60 * MINUTES * 3;
|
||||
pub const CooloffPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
|
||||
}
|
||||
|
||||
impl democracy::Trait for Runtime {
|
||||
@@ -259,26 +271,35 @@ impl democracy::Trait for Runtime {
|
||||
type VotingPeriod = VotingPeriod;
|
||||
type EmergencyVotingPeriod = EmergencyVotingPeriod;
|
||||
type MinimumDeposit = MinimumDeposit;
|
||||
type ExternalOrigin = collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilInstance>;
|
||||
type ExternalMajorityOrigin = collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilInstance>;
|
||||
type ExternalPushOrigin = collective::EnsureProportionAtLeast<_2, _3, AccountId, TechnicalInstance>;
|
||||
type EmergencyOrigin = collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilInstance>;
|
||||
type CancellationOrigin = collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilInstance>;
|
||||
type VetoOrigin = collective::EnsureMember<AccountId, CouncilInstance>;
|
||||
/// A straight majority of the council can decide what their next motion is.
|
||||
type ExternalOrigin = collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>;
|
||||
/// A super-majority can have the next scheduled referendum be a straight majority-carries vote.
|
||||
type ExternalMajorityOrigin = collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>;
|
||||
/// A unanimous council can have the next scheduled referendum be a straight default-carries
|
||||
/// (NTB) vote.
|
||||
type ExternalDefaultOrigin = collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilCollective>;
|
||||
/// Two thirds of the technical committee can have an ExternalMajority/ExternalDefault vote
|
||||
/// be tabled immediately and with a shorter voting/enactment period.
|
||||
type FastTrackOrigin = collective::EnsureProportionAtLeast<_2, _3, AccountId, TechnicalCollective>;
|
||||
// To cancel a proposal which has been passed, 2/3 of the council must agree to it.
|
||||
type CancellationOrigin = collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>;
|
||||
// Any single technical committee member may veto a coming council proposal, however they can
|
||||
// only do it once and it lasts only for the cooloff period.
|
||||
type VetoOrigin = collective::EnsureMember<AccountId, TechnicalCollective>;
|
||||
type CooloffPeriod = CooloffPeriod;
|
||||
}
|
||||
|
||||
type CouncilInstance = collective::Instance1;
|
||||
impl collective::Trait<CouncilInstance> for Runtime {
|
||||
type CouncilCollective = collective::Instance1;
|
||||
impl collective::Trait<CouncilCollective> for Runtime {
|
||||
type Origin = Origin;
|
||||
type Proposal = Call;
|
||||
type Event = Event;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const CandidacyBond: Balance = 10 * BUCKS;
|
||||
pub const VotingBond: Balance = 1 * BUCKS;
|
||||
pub const VotingFee: Balance = 2 * BUCKS;
|
||||
pub const CandidacyBond: Balance = 10 * DOLLARS;
|
||||
pub const VotingBond: Balance = 1 * DOLLARS;
|
||||
pub const VotingFee: Balance = 2 * DOLLARS;
|
||||
pub const PresentSlashPerVoter: Balance = 1 * CENTS;
|
||||
pub const CarryCount: u32 = 6;
|
||||
// one additional vote should go by before an inactive voter can be reaped.
|
||||
@@ -305,24 +326,34 @@ impl elections::Trait for Runtime {
|
||||
type DecayRatio = DecayRatio;
|
||||
}
|
||||
|
||||
type TechnicalInstance = collective::Instance2;
|
||||
impl collective::Trait<TechnicalInstance> for Runtime {
|
||||
type TechnicalCollective = collective::Instance2;
|
||||
impl collective::Trait<TechnicalCollective> for Runtime {
|
||||
type Origin = Origin;
|
||||
type Proposal = Call;
|
||||
type Event = Event;
|
||||
}
|
||||
|
||||
impl membership::Trait<membership::Instance1> for Runtime {
|
||||
type Event = Event;
|
||||
type AddOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
|
||||
type RemoveOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
|
||||
type SwapOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
|
||||
type ResetOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
|
||||
type MembershipInitialized = TechnicalCommittee;
|
||||
type MembershipChanged = TechnicalCommittee;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const ProposalBond: Permill = Permill::from_percent(5);
|
||||
pub const ProposalBondMinimum: Balance = 1 * BUCKS;
|
||||
pub const ProposalBondMinimum: Balance = 1 * DOLLARS;
|
||||
pub const SpendPeriod: BlockNumber = 1 * DAYS;
|
||||
pub const Burn: Permill = Permill::from_percent(50);
|
||||
}
|
||||
|
||||
impl treasury::Trait for Runtime {
|
||||
type Currency = Balances;
|
||||
type ApproveOrigin = collective::EnsureMembers<_4, AccountId, CouncilInstance>;
|
||||
type RejectOrigin = collective::EnsureMembers<_2, AccountId, CouncilInstance>;
|
||||
type ApproveOrigin = collective::EnsureMembers<_4, AccountId, CouncilCollective>;
|
||||
type RejectOrigin = collective::EnsureMembers<_2, AccountId, CouncilCollective>;
|
||||
type Event = Event;
|
||||
type MintedForSpending = ();
|
||||
type ProposalRejection = ();
|
||||
@@ -332,6 +363,12 @@ impl treasury::Trait for Runtime {
|
||||
type Burn = Burn;
|
||||
}
|
||||
|
||||
impl im_online::Trait for Runtime {
|
||||
type Call = Call;
|
||||
type Event = Event;
|
||||
type UncheckedExtrinsic = UncheckedExtrinsic;
|
||||
}
|
||||
|
||||
impl grandpa::Trait for Runtime {
|
||||
type Event = Event;
|
||||
}
|
||||
@@ -347,6 +384,10 @@ impl finality_tracker::Trait for Runtime {
|
||||
type ReportLatency = ReportLatency;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const AttestationPeriod: BlockNumber = 50;
|
||||
}
|
||||
|
||||
impl attestations::Trait for Runtime {
|
||||
type AttestationPeriod = AttestationPeriod;
|
||||
type ValidatorIdentities = parachains::ValidatorIdentities<Runtime>;
|
||||
@@ -395,8 +436,8 @@ construct_runtime!(
|
||||
UncheckedExtrinsic = UncheckedExtrinsic
|
||||
{
|
||||
System: system::{Module, Call, Storage, Config, Event},
|
||||
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
|
||||
Timestamp: timestamp::{Module, Call, Storage, Inherent},
|
||||
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
|
||||
Authorship: authorship::{Module, Call, Storage},
|
||||
Indices: indices,
|
||||
Balances: balances,
|
||||
@@ -406,6 +447,7 @@ construct_runtime!(
|
||||
Council: collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
|
||||
TechnicalCommittee: collective::<Instance2>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
|
||||
Elections: elections::{Module, Call, Storage, Event<T>, Config<T>},
|
||||
TechnicalMembership: membership::<Instance1>::{Module, Call, Storage, Event<T>, Config<T>},
|
||||
FinalityTracker: finality_tracker::{Module, Call, Inherent},
|
||||
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
|
||||
CuratedGrandpa: curated_grandpa::{Module, Call, Config<T>, Storage},
|
||||
@@ -415,6 +457,7 @@ construct_runtime!(
|
||||
Slots: slots::{Module, Call, Storage, Event<T>},
|
||||
Claims: claims::{Module, Call, Storage, Event<T>, Config<T>, ValidateUnsigned},
|
||||
Sudo: sudo,
|
||||
ImOnline: im_online::{Module, Call, Storage, Event, ValidateUnsigned, Config<T>},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -430,6 +473,7 @@ pub type SignedBlock = generic::SignedBlock<Block>;
|
||||
pub type BlockId = generic::BlockId<Block>;
|
||||
/// The SignedExtension to the basic transaction logic.
|
||||
pub type SignedExtra = (
|
||||
system::CheckGenesis<Runtime>,
|
||||
system::CheckEra<Runtime>,
|
||||
system::CheckNonce<Runtime>,
|
||||
system::CheckWeight<Runtime>,
|
||||
@@ -499,7 +543,7 @@ impl_runtime_apis! {
|
||||
|
||||
impl parachain::ParachainHost<Block> for Runtime {
|
||||
fn validators() -> Vec<parachain::ValidatorId> {
|
||||
Aura::authorities() // only possible as long as parachain validator crypto === aura crypto
|
||||
Parachains::authorities()
|
||||
}
|
||||
fn duty_roster() -> parachain::DutyRoster {
|
||||
Parachains::calculate_duty_roster().0
|
||||
@@ -531,19 +575,40 @@ impl_runtime_apis! {
|
||||
None // disable forced changes.
|
||||
}
|
||||
|
||||
fn grandpa_authorities() -> Vec<(SessionKey, u64)> {
|
||||
fn grandpa_authorities() -> Vec<(GrandpaId, u64)> {
|
||||
Grandpa::grandpa_authorities()
|
||||
}
|
||||
}
|
||||
|
||||
impl consensus_aura::AuraApi<Block, AuraId> for Runtime {
|
||||
fn slot_duration() -> u64 {
|
||||
Aura::slot_duration()
|
||||
impl babe_primitives::BabeApi<Block> for Runtime {
|
||||
fn startup_data() -> babe_primitives::BabeConfiguration {
|
||||
// The choice of `c` parameter (where `1 - c` represents the
|
||||
// probability of a slot being empty), is done in accordance to the
|
||||
// slot duration and expected target block time, for safely
|
||||
// resisting network delays of maximum two seconds.
|
||||
// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
|
||||
babe_primitives::BabeConfiguration {
|
||||
median_required_blocks: 1000,
|
||||
slot_duration: Babe::slot_duration(),
|
||||
c: (278, 1000),
|
||||
}
|
||||
}
|
||||
|
||||
fn authorities() -> Vec<AuraId> {
|
||||
Aura::authorities()
|
||||
fn epoch() -> babe_primitives::Epoch {
|
||||
babe_primitives::Epoch {
|
||||
start_slot: Babe::epoch_start_slot(),
|
||||
authorities: Babe::authorities(),
|
||||
epoch_index: Babe::epoch_index(),
|
||||
randomness: Babe::randomness(),
|
||||
duration: EpochDuration::get(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl substrate_session::SessionKeys<Block> for Runtime {
|
||||
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
|
||||
let seed = seed.as_ref().map(|s| rstd::str::from_utf8(&s).expect("Seed is an utf8 string"));
|
||||
SessionKeys::generate(seed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@
|
||||
|
||||
use rstd::prelude::*;
|
||||
use rstd::collections::btree_map::BTreeMap;
|
||||
use parity_codec::{Encode, Decode, HasCompact};
|
||||
use codec::{Encode, Decode, HasCompact};
|
||||
use srml_support::{decl_storage, decl_module, fail, ensure};
|
||||
|
||||
use sr_primitives::traits::{Hash as HashT, BlakeTwo256, Member, CheckedConversion, Saturating, One};
|
||||
use sr_primitives::weights::SimpleDispatchInfo;
|
||||
use primitives::{Hash, Balance, ParachainPublic, parachain::{
|
||||
use primitives::{Hash, Balance, parachain::{
|
||||
self, Id as ParaId, Chain, DutyRoster, AttestedCandidate, Statement, AccountIdConversion,
|
||||
ParachainDispatchOrigin, UpwardMessage, BlockIngressRoots,
|
||||
ParachainDispatchOrigin, UpwardMessage, BlockIngressRoots, ValidatorId
|
||||
}};
|
||||
use {system, session};
|
||||
use srml_support::{
|
||||
@@ -33,9 +33,6 @@ use srml_support::{
|
||||
traits::{Currency, Get, WithdrawReason, ExistenceRequirement}
|
||||
};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use srml_support::storage::hashed::generator;
|
||||
|
||||
use inherents::{ProvideInherent, InherentData, RuntimeString, MakeFatalError, InherentIdentifier};
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
@@ -217,7 +214,7 @@ const WATERMARK_QUEUE_SIZE: usize = 20000;
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as Parachains {
|
||||
/// All authorities' keys at the moment.
|
||||
pub Authorities get(authorities) config(authorities): Vec<ParachainPublic>;
|
||||
pub Authorities get(authorities) config(authorities): Vec<ValidatorId>;
|
||||
/// Vector of all parachain IDs.
|
||||
pub Parachains get(active_parachains): Vec<ParaId>;
|
||||
/// The parachains registered at present.
|
||||
@@ -252,27 +249,33 @@ decl_storage! {
|
||||
add_extra_genesis {
|
||||
config(parachains): Vec<(ParaId, Vec<u8>, Vec<u8>)>;
|
||||
config(_phdata): PhantomData<T>;
|
||||
build(|storage: &mut StorageOverlay, _: &mut ChildrenStorageOverlay, config: &GenesisConfig<T>| {
|
||||
use sr_primitives::traits::Zero;
|
||||
|
||||
let mut p = config.parachains.clone();
|
||||
p.sort_unstable_by_key(|&(ref id, _, _)| *id);
|
||||
p.dedup_by_key(|&mut (ref id, _, _)| *id);
|
||||
|
||||
let only_ids: Vec<_> = p.iter().map(|&(ref id, _, _)| id).cloned().collect();
|
||||
|
||||
<Parachains as generator::StorageValue<_>>::put(&only_ids, storage);
|
||||
|
||||
for (id, code, genesis) in p {
|
||||
// no ingress -- a chain cannot be routed to until it is live.
|
||||
<Code as generator::StorageMap<_, _>>::insert(&id, &code, storage);
|
||||
<Heads as generator::StorageMap<_, _>>::insert(&id, &genesis, storage);
|
||||
<Watermarks<T> as generator::StorageMap<_, _>>::insert(&id, &Zero::zero(), storage);
|
||||
}
|
||||
});
|
||||
build(build::<T>);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
fn build<T: Trait>(
|
||||
storage: &mut (StorageOverlay, ChildrenStorageOverlay),
|
||||
config: &GenesisConfig<T>
|
||||
) {
|
||||
let mut p = config.parachains.clone();
|
||||
p.sort_unstable_by_key(|&(ref id, _, _)| *id);
|
||||
p.dedup_by_key(|&mut (ref id, _, _)| *id);
|
||||
|
||||
let only_ids: Vec<ParaId> = p.iter().map(|&(ref id, _, _)| id).cloned().collect();
|
||||
|
||||
sr_io::with_storage(storage, || {
|
||||
Parachains::put(&only_ids);
|
||||
|
||||
for (id, code, genesis) in p {
|
||||
// no ingress -- a chain cannot be routed to until it is live.
|
||||
Code::insert(&id, &code);
|
||||
Heads::insert(&id, &genesis);
|
||||
<Watermarks<T>>::insert(&id, &sr_primitives::traits::Zero::zero());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
/// Parachains module.
|
||||
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {
|
||||
@@ -380,7 +383,7 @@ impl<T: Trait> Module<T> {
|
||||
origin: ParachainDispatchOrigin,
|
||||
data: &[u8],
|
||||
) {
|
||||
if let Some(message_call) = T::Call::decode(&mut &data[..]) {
|
||||
if let Ok(message_call) = <T as Trait>::Call::decode(&mut &data[..]) {
|
||||
let origin: <T as Trait>::Origin = match origin {
|
||||
ParachainDispatchOrigin::Signed =>
|
||||
system::RawOrigin::Signed(id.into_account()).into(),
|
||||
@@ -528,6 +531,7 @@ impl<T: Trait> Module<T> {
|
||||
pub fn calculate_duty_roster() -> (DutyRoster, [u8; 32]) {
|
||||
let parachains = Self::active_parachains();
|
||||
let parachain_count = parachains.len();
|
||||
// TODO: use decode length. substrate #2794
|
||||
let validator_count = Self::authorities().len();
|
||||
let validators_per_parachain = if parachain_count != 0 { (validator_count - 1) / parachain_count } else { 0 };
|
||||
|
||||
@@ -561,12 +565,12 @@ impl<T: Trait> Module<T> {
|
||||
let orig_seed = seed.clone().to_fixed_bytes();
|
||||
|
||||
// shuffle
|
||||
for i in 0..(validator_count - 1) {
|
||||
for i in 0..(validator_count.saturating_sub(1)) {
|
||||
// 4 bytes of entropy used per cycle, 32 bytes entropy per hash
|
||||
let offset = (i * 4 % 32) as usize;
|
||||
|
||||
// number of roles remaining to select from.
|
||||
let remaining = (validator_count - i) as usize;
|
||||
let remaining = rstd::cmp::max(1, (validator_count - i) as usize);
|
||||
|
||||
// 8 32-bit ints per 256-bit seed.
|
||||
let val_index = u32::decode(&mut &seed[offset..offset + 4])
|
||||
@@ -656,7 +660,7 @@ impl<T: Trait> Module<T> {
|
||||
-> rstd::result::Result<IncludedBlocks<T>, &'static str>
|
||||
{
|
||||
use primitives::parachain::ValidityAttestation;
|
||||
use sr_primitives::traits::Verify;
|
||||
use sr_primitives::traits::AppVerify;
|
||||
|
||||
// returns groups of slices that have the same chain ID.
|
||||
// assumes the inner slice is sorted by id.
|
||||
@@ -801,7 +805,7 @@ impl<T: Trait> Module<T> {
|
||||
|
||||
para_block_hashes.push(candidate_hash.unwrap_or_else(|| candidate.candidate().hash()));
|
||||
|
||||
ensure!(
|
||||
ensure!(
|
||||
candidate.validity_votes.len() == expected_votes_len,
|
||||
"Extra untagged validity votes along with candidate"
|
||||
);
|
||||
@@ -834,7 +838,7 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
|
||||
impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
|
||||
type Key = ParachainPublic;
|
||||
type Key = ValidatorId;
|
||||
|
||||
fn on_new_session<'a, I: 'a>(changed: bool, validators: I, _queued: I)
|
||||
where I: Iterator<Item=(&'a T::AccountId, Self::Key)>
|
||||
@@ -881,10 +885,11 @@ mod tests {
|
||||
testing::{UintAuthorityId, Header},
|
||||
};
|
||||
use primitives::{
|
||||
parachain::{CandidateReceipt, HeadData, ValidityAttestation}, SessionKey,
|
||||
BlockNumber, AuraId,
|
||||
parachain::{CandidateReceipt, HeadData, ValidityAttestation, ValidatorId},
|
||||
BlockNumber,
|
||||
};
|
||||
use keyring::Ed25519Keyring;
|
||||
use crate::constants::time::*;
|
||||
use keyring::Sr25519Keyring;
|
||||
use srml_support::{
|
||||
impl_outer_origin, impl_outer_dispatch, assert_ok, assert_err, parameter_types,
|
||||
};
|
||||
@@ -905,13 +910,14 @@ mod tests {
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct Test;
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub const BlockHashCount: u32 = 250;
|
||||
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
|
||||
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
|
||||
}
|
||||
impl system::Trait for Test {
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -957,9 +963,14 @@ mod tests {
|
||||
type MinimumPeriod = MinimumPeriod;
|
||||
}
|
||||
|
||||
impl aura::Trait for Test {
|
||||
type HandleReport = aura::StakingSlasher<Test>;
|
||||
type AuthorityId = AuraId;
|
||||
parameter_types! {
|
||||
pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS;
|
||||
pub const ExpectedBlockTime: u64 = MILLISECS_PER_BLOCK;
|
||||
}
|
||||
|
||||
impl babe::Trait for Test {
|
||||
type EpochDuration = EpochDuration;
|
||||
type ExpectedBlockTime = ExpectedBlockTime;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -989,7 +1000,7 @@ mod tests {
|
||||
parameter_types! {
|
||||
pub const SessionsPerEra: session::SessionIndex = 6;
|
||||
pub const BondingDuration: staking::EraIndex = 24 * 28;
|
||||
pub const AttestationPeriod: u64 = 100;
|
||||
pub const AttestationPeriod: BlockNumber = 100;
|
||||
}
|
||||
|
||||
impl staking::Trait for Test {
|
||||
@@ -1021,17 +1032,19 @@ mod tests {
|
||||
|
||||
fn new_test_ext(parachains: Vec<(ParaId, Vec<u8>, Vec<u8>)>) -> TestExternalities<Blake2Hasher> {
|
||||
use staking::StakerStatus;
|
||||
use babe::AuthorityId as BabeAuthorityId;
|
||||
|
||||
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
|
||||
let (mut t, mut c) = system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
let authority_keys = [
|
||||
Ed25519Keyring::Alice,
|
||||
Ed25519Keyring::Bob,
|
||||
Ed25519Keyring::Charlie,
|
||||
Ed25519Keyring::Dave,
|
||||
Ed25519Keyring::Eve,
|
||||
Ed25519Keyring::Ferdie,
|
||||
Ed25519Keyring::One,
|
||||
Ed25519Keyring::Two,
|
||||
Sr25519Keyring::Alice,
|
||||
Sr25519Keyring::Bob,
|
||||
Sr25519Keyring::Charlie,
|
||||
Sr25519Keyring::Dave,
|
||||
Sr25519Keyring::Eve,
|
||||
Sr25519Keyring::Ferdie,
|
||||
Sr25519Keyring::One,
|
||||
Sr25519Keyring::Two,
|
||||
];
|
||||
|
||||
// stashes are the index.
|
||||
@@ -1039,7 +1052,11 @@ mod tests {
|
||||
.map(|(i, _k)| (i as u64, UintAuthorityId(i as u64)))
|
||||
.collect();
|
||||
|
||||
let authorities: Vec<_> = authority_keys.iter().map(|k| SessionKey::from(*k)).collect();
|
||||
let authorities: Vec<_> = authority_keys.iter().map(|k| ValidatorId::from(k.public())).collect();
|
||||
let babe_authorities: Vec<_> = authority_keys.iter()
|
||||
.map(|k| BabeAuthorityId::from(k.public()))
|
||||
.map(|k| (k, 1))
|
||||
.collect();
|
||||
|
||||
// controllers are the index + 1000
|
||||
let stakers: Vec<_> = (0..authority_keys.len()).map(|i| (
|
||||
@@ -1051,23 +1068,24 @@ mod tests {
|
||||
|
||||
let balances: Vec<_> = (0..authority_keys.len()).map(|i| (i as u64, 10_000_000)).collect();
|
||||
|
||||
session::GenesisConfig::<Test> {
|
||||
keys: session_keys,
|
||||
}.assimilate_storage(&mut t, &mut c).unwrap();
|
||||
GenesisConfig::<Test> {
|
||||
parachains,
|
||||
authorities: authorities.clone(),
|
||||
_phdata: Default::default(),
|
||||
}.assimilate_storage(&mut t, &mut c).unwrap();
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
|
||||
aura::GenesisConfig::<Test> {
|
||||
authorities,
|
||||
}.assimilate_storage(&mut t, &mut c).unwrap();
|
||||
session::GenesisConfig::<Test> {
|
||||
keys: session_keys,
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
|
||||
babe::GenesisConfig {
|
||||
authorities: babe_authorities,
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
|
||||
balances::GenesisConfig::<Test> {
|
||||
balances,
|
||||
vesting: vec![],
|
||||
}.assimilate_storage(&mut t, &mut c).unwrap();
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
|
||||
staking::GenesisConfig::<Test> {
|
||||
current_era: 0,
|
||||
@@ -1077,7 +1095,7 @@ mod tests {
|
||||
offline_slash: Perbill::from_percent(5),
|
||||
offline_slash_grace: 0,
|
||||
invulnerables: vec![],
|
||||
}.assimilate_storage(&mut t, &mut c).unwrap();
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
|
||||
t.into()
|
||||
}
|
||||
@@ -1094,8 +1112,10 @@ mod tests {
|
||||
let candidate_hash = candidate.candidate.hash();
|
||||
|
||||
let authorities = Parachains::authorities();
|
||||
let extract_key = |public: SessionKey| {
|
||||
Ed25519Keyring::from_raw_public(public.0).unwrap()
|
||||
let extract_key = |public: ValidatorId| {
|
||||
let mut raw_public = [0; 32];
|
||||
raw_public.copy_from_slice(public.as_ref());
|
||||
Sr25519Keyring::from_raw_public(raw_public).unwrap()
|
||||
};
|
||||
|
||||
let validation_entries = duty_roster.validator_duty.iter()
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
use rstd::{result, ops::Add, convert::{TryFrom, TryInto}};
|
||||
use sr_primitives::traits::CheckedSub;
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
/// Total number of possible sub ranges of slots.
|
||||
pub const SLOT_RANGE_COUNT: usize = 10;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
use rstd::{prelude::*, mem::swap, convert::TryInto};
|
||||
use sr_primitives::traits::{CheckedSub, StaticLookup, Zero, One, CheckedConversion, Hash};
|
||||
use sr_primitives::weights::SimpleDispatchInfo;
|
||||
use parity_codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
use srml_support::{
|
||||
decl_module, decl_storage, decl_event, StorageValue, StorageMap, ensure,
|
||||
traits::{Currency, ReservableCurrency, WithdrawReason, ExistenceRequirement, Get}
|
||||
@@ -813,13 +813,14 @@ mod tests {
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct Test;
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub const BlockHashCount: u32 = 250;
|
||||
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
|
||||
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
|
||||
}
|
||||
impl system::Trait for Test {
|
||||
type Origin = Origin;
|
||||
type Call = ();
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -926,11 +927,11 @@ mod tests {
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
// our desired mock up.
|
||||
fn new_test_ext() -> sr_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap().0;
|
||||
t.extend(balances::GenesisConfig::<Test>{
|
||||
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
balances::GenesisConfig::<Test>{
|
||||
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
|
||||
vesting: vec![],
|
||||
}.build_storage().unwrap().0);
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
t.into()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user