Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
35e4cb5
remove v0 parachains modules and switch to v1 primitives
rphmeier Jul 30, 2020
7ec0e79
get tests compiling for runtime-common
rphmeier Jul 30, 2020
25de026
remove registrar module
rphmeier Jul 30, 2020
0798117
Add a dummy module
rphmeier Jul 30, 2020
721bd09
remove runtime-parachains
rphmeier Jul 30, 2020
ea76293
mostly remove old parachains code from polkadot-runtime
rphmeier Jul 30, 2020
bb2ddff
remove slots::Trait implementation
rphmeier Jul 30, 2020
edfe078
remove sp_std prelude import
rphmeier Jul 30, 2020
933903b
Merge branch 'master' into rh-remove-v0-runtime
rphmeier Jul 30, 2020
96e8b8a
add a ZeroSizedTypeDifferentiator to dummy
rphmeier Jul 30, 2020
5bbb31e
finish porting over polkadot runtime
rphmeier Jul 30, 2020
03d1452
ZeroSizedTypeDifferentiator was actually unnecessary
rphmeier Jul 30, 2020
c532a8f
westend
rphmeier Jul 31, 2020
19fca5a
kusama
rphmeier Jul 31, 2020
5c98706
Merge branch 'master' into rh-remove-v0-runtime
rphmeier Jul 31, 2020
60fd854
test-runtime (no dummy modules)
rphmeier Jul 31, 2020
5fd65f6
fix warning
rphmeier Jul 31, 2020
0f69588
fix chain-specs
rphmeier Jul 31, 2020
c2e1630
fix test-service
rphmeier Jul 31, 2020
5ec4bb7
test-client
rphmeier Aug 1, 2020
f7cec7d
remove dead import
rphmeier Aug 2, 2020
96ae647
remove unused needed_extrinsics parameter
rphmeier Aug 2, 2020
3d0db7a
Merge branch 'master' into rh-remove-v0-runtime
rphmeier Aug 12, 2020
ef2bc6a
runtimes compile
rphmeier Aug 12, 2020
c1b1ab4
remove rococo-v0
rphmeier Aug 12, 2020
dbcabb3
remove remaining references to Rococo
rphmeier Aug 12, 2020
32c035d
bump versions
rphmeier Aug 12, 2020
fb51b40
Merge branch 'master' into rh-remove-v0-runtime
rphmeier Aug 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
kusama
  • Loading branch information
rphmeier committed Jul 31, 2020
commit 19fca5ad5ec1c3710c25abc6098a75fac21e1196
185 changes: 59 additions & 126 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@
use sp_std::prelude::*;
use sp_core::u32_trait::{_1, _2, _3, _4, _5};
use codec::{Encode, Decode};
use primitives::v0::{
self as parachain,
use primitives::v1::{
AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment,
ActiveParas, AbridgedCandidateReceipt, SigningContext,
};
use primitives::v0 as p_v0;
use runtime_common::{
attestations, claims, parachains, registrar, slots, SlowAdjustingFeeUpdate,
dummy, claims, SlowAdjustingFeeUpdate,
impls::{CurrencyToVoteHandler, ToAuthor},
NegativeImbalance, BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength, BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight,
MaximumExtrinsicWeight,
MaximumExtrinsicWeight, ParachainSessionKeyPlaceholder,
};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, ModuleId,
Expand Down Expand Up @@ -71,8 +70,6 @@ pub use staking::StakerStatus;
pub use sp_runtime::BuildStorage;
pub use timestamp::Call as TimestampCall;
pub use balances::Call as BalancesCall;
pub use attestations::{Call as AttestationsCall, MORE_ATTESTATIONS_IDENTIFIER};
pub use parachains::Call as ParachainsCall;

/// Constant values used within the runtime.
pub mod constants;
Expand Down Expand Up @@ -111,8 +108,8 @@ pub fn native_version() -> NativeVersion {
/// Avoid processing transactions from slots and parachain registrar.
pub struct BaseFilter;
impl Filter<Call> for BaseFilter {
fn filter(call: &Call) -> bool {
!matches!(call, Call::Slots(_) | Call::Registrar(_))
fn filter(_: &Call) -> bool {
true
}
}

Expand Down Expand Up @@ -269,7 +266,7 @@ impl_opaque_keys! {
pub grandpa: Grandpa,
pub babe: Babe,
pub im_online: ImOnline,
pub parachain_validator: Parachains,
pub parachain_validator: ParachainSessionKeyPlaceholder<Runtime>,
pub authority_discovery: AuthorityDiscovery,
}
}
Expand Down Expand Up @@ -577,47 +574,6 @@ 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>;
type RewardAttestation = Staking;
}

parameter_types! {
pub const MaxCodeSize: u32 = 10 * 1024 * 1024; // 10 MB
pub const MaxHeadDataSize: u32 = 20 * 1024; // 20 KB
pub const ValidationUpgradeFrequency: BlockNumber = 2 * DAYS;
pub const ValidationUpgradeDelay: BlockNumber = 8 * HOURS;
pub const SlashPeriod: BlockNumber = 7 * DAYS;
}

impl parachains::Trait for Runtime {
type AuthorityId = primitives::v0::fisherman::FishermanAppCrypto;
type Origin = Origin;
type Call = Call;
type ParachainCurrency = Balances;
type BlockNumberConversion = sp_runtime::traits::Identity;
type Randomness = RandomnessCollectiveFlip;
type ActiveParachains = Registrar;
type Registrar = Registrar;
type MaxCodeSize = MaxCodeSize;
type MaxHeadDataSize = MaxHeadDataSize;

type ValidationUpgradeFrequency = ValidationUpgradeFrequency;
type ValidationUpgradeDelay = ValidationUpgradeDelay;
type SlashPeriod = SlashPeriod;

type Proof = sp_session::MembershipProof;
type KeyOwnerProofSystem = session::historical::Module<Self>;
type IdentificationTuple = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, Vec<u8>)>>::IdentificationTuple;
type ReportOffence = Offences;
type BlockHashConversion = sp_runtime::traits::Identity;
}

/// Submits transaction with the node's public and signature type. Adheres to the signed extension
/// format of the chain.
impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
Expand Down Expand Up @@ -649,8 +605,6 @@ impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime
system::CheckNonce::<Runtime>::from(nonce),
system::CheckWeight::<Runtime>::new(),
transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
registrar::LimitParathreadCommits::<Runtime>::new(),
parachains::ValidateDoubleVoteReports::<Runtime>::new(),
);
let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
debug::warn!("Unable to create signed payload: {:?}", e);
Expand All @@ -675,36 +629,6 @@ impl<C> system::offchain::SendTransactionTypes<C> for Runtime where
type Extrinsic = UncheckedExtrinsic;
}

parameter_types! {
pub const ParathreadDeposit: Balance = 5 * DOLLARS;
pub const QueueSize: usize = 2;
pub const MaxRetries: u32 = 3;
}

impl registrar::Trait for Runtime {
type Event = Event;
type Origin = Origin;
type Currency = Balances;
type ParathreadDeposit = ParathreadDeposit;
type SwapAux = Slots;
type QueueSize = QueueSize;
type MaxRetries = MaxRetries;
}

parameter_types! {
pub const LeasePeriod: BlockNumber = 100_000;
pub const EndingPeriod: BlockNumber = 1000;
}

impl slots::Trait for Runtime {
type Event = Event;
type Currency = Balances;
type Parachains = Registrar;
type LeasePeriod = LeasePeriod;
type EndingPeriod = EndingPeriod;
type Randomness = RandomnessCollectiveFlip;
}

parameter_types! {
pub Prefix: &'static [u8] = b"Pay KSMs to the Kusama account:";
}
Expand Down Expand Up @@ -830,6 +754,8 @@ parameter_types! {
pub const MaxProxies: u16 = 32;
}

impl<I: dummy::Instance> dummy::Trait<I> for Runtime { }

/// The type used to represent the kinds of proxying allowed.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug)]
pub enum ProxyType {
Expand Down Expand Up @@ -868,10 +794,10 @@ impl InstanceFilter<Call> for ProxyType {
Call::TechnicalMembership(..) |
Call::Treasury(..) |
Call::Claims(..) |
Call::Parachains(..) |
Call::Attestations(..) |
Call::Slots(..) |
Call::Registrar(..) |
Call::DummyParachains(..) |
Call::DummyAttestations(..) |
Call::DummySlots(..) |
Call::DummyRegistrar(..) |
Call::Utility(..) |
Call::Identity(..) |
Call::Society(..) |
Expand Down Expand Up @@ -938,7 +864,7 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = primitives::v0::Block,
NodeBlock = primitives::v1::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
// Basic stuff; balances is uncallable initially.
Expand Down Expand Up @@ -975,12 +901,11 @@ construct_runtime! {
// Claims. Usable initially.
Claims: claims::{Module, Call, Storage, Event<T>, Config<T>, ValidateUnsigned},

// Parachains stuff; slots are disabled (no auctions initially). The rest are safe as they
// have no public dispatchables.
Parachains: parachains::{Module, Call, Storage, Config, Inherent, Origin},
Attestations: attestations::{Module, Call, Storage},
Slots: slots::{Module, Call, Storage, Event<T>},
Registrar: registrar::{Module, Call, Storage, Event, Config<T>},
// Old parachains stuff. All dummies to avoid messing up the transaction indices.
DummyParachains: dummy::<Instance0>::{Module, Call},
DummyAttestations: dummy::<Instance1>::{Module, Call},
DummySlots: dummy::<Instance2>::{Module, Call},
DummyRegistrar: dummy::<Instance3>::{Module, Call},

// Utility module.
Utility: utility::{Module, Call, Event},
Expand Down Expand Up @@ -1027,8 +952,6 @@ pub type SignedExtra = (
system::CheckNonce<Runtime>,
system::CheckWeight<Runtime>,
transaction_payment::ChargeTransactionPayment<Runtime>,
registrar::LimitParathreadCommits<Runtime>,
parachains::ValidateDoubleVoteReports<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
Expand Down Expand Up @@ -1108,45 +1031,55 @@ sp_api::impl_runtime_apis! {
}
}

impl parachain::ParachainHost<Block> for Runtime {
fn validators() -> Vec<parachain::ValidatorId> {
Parachains::authorities()
// Dummy implementation to continue supporting old parachains runtime temporarily.
impl p_v0::ParachainHost<Block> for Runtime {
fn validators() -> Vec<p_v0::ValidatorId> {
// this is a compile-time check of size equality. note that we don't invoke
// the function and nothing here is unsafe.
let _ = core::mem::transmute::<p_v0::ValidatorId, AccountId>;

// Yes, these aren't actually the parachain session keys.
// It doesn't matter, but we shouldn't return a zero-sized vector here.
// As there are no parachains
Session::validators()
.into_iter()
.map(|k| k.using_encoded(|s| Decode::decode(&mut &s[..]))
.expect("correct size and raw-bytes; qed"))
.collect()
}
fn duty_roster() -> parachain::DutyRoster {
Parachains::calculate_duty_roster().0
fn duty_roster() -> p_v0::DutyRoster {
let v = Session::validators();
p_v0::DutyRoster { validator_duty: (0..v.len()).map(|_| p_v0::Chain::Relay).collect() }
}
fn active_parachains() -> Vec<(parachain::Id, Option<(parachain::CollatorId, parachain::Retriable)>)> {
Registrar::active_paras()
fn active_parachains() -> Vec<(p_v0::Id, Option<(p_v0::CollatorId, p_v0::Retriable)>)> {
Vec::new()
}
fn global_validation_data() -> parachain::GlobalValidationData {
Parachains::global_validation_data()
fn global_validation_data() -> p_v0::GlobalValidationData {
p_v0::GlobalValidationData {
max_code_size: 1,
max_head_data_size: 1,
block_number: System::block_number().saturating_sub(1),
}
}
fn local_validation_data(id: parachain::Id) -> Option<parachain::LocalValidationData> {
Parachains::current_local_validation_data(&id)
fn local_validation_data(_id: p_v0::Id) -> Option<p_v0::LocalValidationData> {
None
}
fn parachain_code(id: parachain::Id) -> Option<parachain::ValidationCode> {
Parachains::parachain_code(&id)
fn parachain_code(_id: p_v0::Id) -> Option<p_v0::ValidationCode> {
None
}
fn get_heads(extrinsics: Vec<<Block as BlockT>::Extrinsic>)
-> Option<Vec<AbridgedCandidateReceipt>>
fn get_heads(_extrinsics: Vec<<Block as BlockT>::Extrinsic>)
-> Option<Vec<p_v0::AbridgedCandidateReceipt>>
{
extrinsics
.into_iter()
.find_map(|ex| match UncheckedExtrinsic::decode(&mut ex.encode().as_slice()) {
Ok(ex) => match ex.function {
Call::Parachains(ParachainsCall::set_heads(heads)) => {
Some(heads.into_iter().map(|c| c.candidate).collect())
}
_ => None,
}
Err(_) => None,
})
None
}
fn signing_context() -> SigningContext {
Parachains::signing_context()
fn signing_context() -> p_v0::SigningContext {
p_v0::SigningContext {
parent_hash: System::parent_hash(),
session_index: Session::current_index(),
}
}
fn downward_messages(id: parachain::Id) -> Vec<primitives::v0::DownwardMessage> {
Parachains::downward_messages(id)
fn downward_messages(_id: p_v0::Id) -> Vec<p_v0::DownwardMessage> {
Vec::new()
}
}

Expand Down