Skip to content

Commit

Permalink
[WIP] Add common coretime parachain to Rococo (#2419)
Browse files Browse the repository at this point in the history
Co-authored-by: eskimor <[email protected]>
  • Loading branch information
antonva and eskimor authored Nov 24, 2023
1 parent 8c1b9a5 commit b9421f3
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions polkadot/runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ sp-npos-elections = { path = "../../../substrate/primitives/npos-elections", def

pallet-authorship = { path = "../../../substrate/frame/authorship", default-features = false }
pallet-balances = { path = "../../../substrate/frame/balances", default-features = false }
pallet-broker = { path = "../../../substrate/frame/broker", default-features = false }
pallet-fast-unstake = { path = "../../../substrate/frame/fast-unstake", default-features = false }
pallet-identity = { path = "../../../substrate/frame/identity", default-features = false }
pallet-session = { path = "../../../substrate/frame/session", default-features = false }
Expand Down Expand Up @@ -84,6 +85,7 @@ std = [
"pallet-asset-rate?/std",
"pallet-authorship/std",
"pallet-balances/std",
"pallet-broker/std",
"pallet-election-provider-multi-phase/std",
"pallet-fast-unstake/std",
"pallet-identity/std",
Expand Down Expand Up @@ -124,6 +126,7 @@ runtime-benchmarks = [
"pallet-asset-rate/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-broker/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
Expand All @@ -148,6 +151,7 @@ try-runtime = [
"pallet-authorship/try-runtime",
"pallet-babe?/try-runtime",
"pallet-balances/try-runtime",
"pallet-broker/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-identity/try-runtime",
Expand Down
150 changes: 150 additions & 0 deletions polkadot/runtime/common/src/coretime/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Copyright (C) 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/>.

//! Extrinsics implementing the relay chain side of the Coretime interface.
//!
//! <https://github.com/polkadot-fellows/RFCs/blob/main/text/0005-coretime-interface.md>
// #[cfg(test)]
// mod tests;

use frame_support::{pallet_prelude::*, traits::Currency};
use frame_system::pallet_prelude::*;
use pallet_broker::CoreAssignment;
use primitives::CoreIndex;
use runtime_parachains::assigner_bulk::{self, PartsOf57600};

use sp_std::prelude::*;

pub use pallet::*;

pub trait WeightInfo {
fn request_core_count() -> Weight;
fn request_revenue_info_at() -> Weight;
fn credit_account() -> Weight;
fn assign_core() -> Weight;
}

/// A weight info that is only suitable for testing.
pub struct TestWeightInfo;

impl WeightInfo for TestWeightInfo {
fn request_core_count() -> Weight {
Weight::MAX
}
fn request_revenue_info_at() -> Weight {
Weight::MAX
}
fn credit_account() -> Weight {
Weight::MAX
}
fn assign_core() -> Weight {
Weight::MAX
}
}

/// Shorthand for the Balance type the runtime is using.
type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

#[frame_support::pallet(dev_mode)]
pub mod pallet {

use super::*;

#[pallet::pallet]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config: frame_system::Config + assigner_bulk::Config {
/// The runtime's definition of a Currency.
type Currency: Currency<Self::AccountId>;
/// Something that provides the weight of this pallet.
//type WeightInfo: WeightInfo;
/// The external origin allowed to enact coretime extrinsics. Usually the broker system
/// parachain.
type ExternalBrokerOrigin: EnsureOrigin<Self::RuntimeOrigin>;
}

#[pallet::error]
pub enum Error<T> {}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}

#[pallet::call]
impl<T: Config> Pallet<T> {
// TODO Impl me!
//#[pallet::weight(<T as Config>::WeightInfo::request_core_count())]
#[pallet::call_index(1)]
pub fn request_core_count(origin: OriginFor<T>, _count: u16) -> DispatchResult {
// Ignore requests not coming from the External Broker parachain.
let _multi_location = <T as Config>::ExternalBrokerOrigin::ensure_origin(origin)?;
Ok(())
}

// TODO Impl me!
//#[pallet::weight(<T as Config>::WeightInfo::request_revenue_info_at())]
#[pallet::call_index(2)]
pub fn request_revenue_info_at(
origin: OriginFor<T>,
_when: BlockNumberFor<T>,
) -> DispatchResult {
// Ignore requests not coming from the External Broker parachain.
let _multi_location = <T as Config>::ExternalBrokerOrigin::ensure_origin(origin)?;
Ok(())
}

// TODO Impl me!
//#[pallet::weight(<T as Config>::WeightInfo::credit_account())]
#[pallet::call_index(3)]
pub fn credit_account(
origin: OriginFor<T>,
_who: T::AccountId,
_amount: BalanceOf<T>,
) -> DispatchResult {
// Ignore requests not coming from the External Broker parachain.
let _multi_location = <T as Config>::ExternalBrokerOrigin::ensure_origin(origin)?;
Ok(())
}

/// Receive instructions from the `ExternalBrokerOrigin`, detailing how a specific core is
/// to be used.
///
/// Parameters:
/// -`origin`: The `ExternalBrokerOrigin`, assumed to be the Broker system parachain.
/// -`core`: The core that should be scheduled.
/// -`begin`: The starting blockheight of the instruction.
/// -`assignment`: How the blockspace should be utilised.
/// -`end_hint`: An optional hint as to when this particular set of instructions will end.
// TODO: Weights!
//#[pallet::weight(<T as Config>::WeightInfo::assign_core())]
#[pallet::call_index(4)]
pub fn assign_core(
origin: OriginFor<T>,
core: CoreIndex,
begin: BlockNumberFor<T>,
assignment: Vec<(CoreAssignment, PartsOf57600)>,
end_hint: Option<BlockNumberFor<T>>,
) -> DispatchResult {
// Ignore requests not coming from the External Broker parachain.
let _multi_location = <T as Config>::ExternalBrokerOrigin::ensure_origin(origin)?;

<assigner_bulk::Pallet<T>>::assign_core(core, begin, assignment, end_hint)
}
}
}
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
pub mod assigned_slots;
pub mod auctions;
pub mod claims;
pub mod coretime;
pub mod crowdloan;
pub mod elections;
pub mod identity_migrator;
Expand Down
5 changes: 5 additions & 0 deletions polkadot/runtime/parachains/src/paras_inherent/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,11 @@ mod enter {
Pallet::<Test>::on_chain_votes().unwrap().session,
2
);

assert_ok!(Pallet::<Test>::enter(
frame_system::RawOrigin::None.into(),
limit_inherent_data,
));
});
}

Expand Down
11 changes: 10 additions & 1 deletion polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#![recursion_limit = "512"]

use pallet_nis::WithMaximumOf;
use pallet_xcm::EnsureXcm;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use primitives::{
slashing, vstaging::NodeFeatures, AccountId, AccountIndex, Balance, BlockNumber,
Expand All @@ -31,7 +32,7 @@ use primitives::{
ValidatorIndex, PARACHAIN_KEY_TYPE_ID,
};
use runtime_common::{
assigned_slots, auctions, claims, crowdloan, identity_migrator, impl_runtime_weights,
assigned_slots, auctions, claims, coretime, crowdloan, identity_migrator, impl_runtime_weights,
impls::{
LocatableAssetConverter, ToAuthor, VersionedLocatableAsset, VersionedMultiLocationConverter,
},
Expand Down Expand Up @@ -125,6 +126,7 @@ use governance::{
pallet_custom_origins, AuctionAdmin, Fellows, GeneralAdmin, LeaseAdmin, Treasurer,
TreasurySpender,
};
use xcm_config::OnlyBroker;

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -992,6 +994,12 @@ impl parachains_assigner_on_demand::Config for Runtime {
type WeightInfo = weights::runtime_parachains_assigner_on_demand::WeightInfo<Runtime>;
}

impl coretime::Config for Runtime {
type Currency = Balances;
//type WeightInfo = weights::runtime_coretime::WeightInfo<Runtime>;
type ExternalBrokerOrigin = EnsureXcm<OnlyBroker>;
}

impl parachains_assigner_bulk::Config for Runtime {}

impl parachains_assigner_parachains::Config for Runtime {}
Expand Down Expand Up @@ -1393,6 +1401,7 @@ construct_runtime! {
Slots: slots::{Pallet, Call, Storage, Event<T>} = 71,
Auctions: auctions::{Pallet, Call, Storage, Event<T>} = 72,
Crowdloan: crowdloan::{Pallet, Call, Storage, Event<T>} = 73,
Coretime: coretime::{Pallet, Call} = 74,

// Pallet for sending XCM.
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config<T>} = 99,
Expand Down
4 changes: 4 additions & 0 deletions polkadot/runtime/rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ match_types! {
pub type OnlyParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(_)) }
};

pub type OnlyBroker: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(BROKER_ID)) }
};
}

/// The barriers one of which must be passed for an XCM message to be executed.
Expand Down
31 changes: 31 additions & 0 deletions polkadot/zombienet_tests/smoke/0004-coretime-smoke-test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[settings]
timeout = 1000

[relaychain]
default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}"
chain = "rococo-local"
command = "polkadot"

[[relaychain.nodes]]
name = "alice"
args = [ "--alice", "-lruntime=debug,parachain=trace" ]

[[relaychain.nodes]]
name = "bob"
args = [ "--bob", "-lruntime=debug,parachain=trace" ]

[[parachains]]
id = 1004
add_to_genesis = false
register_para = true

[parachains.collator]
name = "coretime-collator"
image = "{{COL_IMAGE}}"
command = "polkadot-parachain"
args = [ "-lruntime=debug,parachain=trace" ]

[types.Header]
number = "u64"
parent_hash = "Hash"
post_state = "Hash"

0 comments on commit b9421f3

Please sign in to comment.